aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/completion.odin32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/server/completion.odin b/src/server/completion.odin
index 5cae51e..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(
@@ -1591,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, ":")