Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix autocomplete for import #360

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/server/completion.odin
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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, ":")

Expand Down
Loading