aboutsummaryrefslogtreecommitdiff
path: root/src/server/completion.odin
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2024-04-22 19:45:37 +0200
committerDanielGavin <danielgavin5@hotmail.com>2024-04-22 19:45:37 +0200
commit21d3473bacfbd8dc81fa855d085a9bb67cc5be01 (patch)
treee4864ecff42ce303677352f5373939c5ee5943a4 /src/server/completion.odin
parent6ce95de7909837c4e03b0338400f0b38ae8c912a (diff)
parent9147dc2f31f38148daaeebd083f7120bb8d6bab0 (diff)
Merge branch 'master' of https://github.com/DanielGavin/ols
Diffstat (limited to 'src/server/completion.odin')
-rw-r--r--src/server/completion.odin37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/server/completion.odin b/src/server/completion.odin
index f917498..8fe924e 100644
--- a/src/server/completion.odin
+++ b/src/server/completion.odin
@@ -52,9 +52,21 @@ get_completion_list :: proc(
return list, true
}
- if position_context.import_stmt == nil &&
- strings.contains_any(completion_context.triggerCharacter, "/:\"") {
- return list, true
+ if position_context.import_stmt == nil {
+ if strings.contains_any(completion_context.triggerCharacter, "/:\"") {
+ return list, true
+ }
+ } else {
+ // Check only when the import fullpath length is > 1, to allow
+ // completion of modules when the initial '"' quote is entered.
+ if len(position_context.import_stmt.fullpath) > 1 &&
+ position_context.position == position_context.import_stmt.end.offset &&
+ completion_context.triggerCharacter == "\"" {
+ // The completion was called for an import statement where the
+ // cursor is on the ending quote, so abort early to prevent
+ // performing another completion.
+ return list, true
+ }
}
ast_context := make_ast_context(
@@ -345,6 +357,10 @@ get_selector_completion :: proc(
}
}
+ receiver_start := position_context.selector.expr_base.pos.offset
+ receiver_end := position_context.selector.expr_base.end.offset
+ receiver := position_context.file.src[receiver_start:receiver_end]
+
if s, ok := selector.value.(SymbolProcedureValue); ok {
if len(s.return_types) == 1 {
if selector, ok = resolve_type_expression(
@@ -362,6 +378,7 @@ get_selector_completion :: proc(
selector,
position_context,
&items,
+ receiver,
)
}
@@ -1586,14 +1603,18 @@ get_package_completion :: proc(
list.isIncomplete = false
- fullpath_length := len(position_context.import_stmt.fullpath)
+ without_quotes := position_context.import_stmt.fullpath
- if fullpath_length <= 1 {
- return
+ // Strip the opening quote, if one exists.
+ if len(without_quotes) > 0 && without_quotes[0] == '"' {
+ without_quotes = without_quotes[1:]
+ }
+
+ // Strip the closing quote, if one exists.
+ if len(without_quotes) > 0 && without_quotes[len(without_quotes) - 1] == '"' {
+ without_quotes = without_quotes[:len(without_quotes) - 1]
}
- without_quotes := position_context.import_stmt.fullpath[1:fullpath_length -
- 1]
absolute_path := without_quotes
colon_index := strings.index(without_quotes, ":")