From 6c6a5031d351bb5a06f48e97b745ef93599b56c0 Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Fri, 19 Apr 2024 14:27:11 -0400 Subject: Fix autocomplete for import --- src/server/completion.odin | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'src') 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, ":") -- cgit v1.2.3