-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: provide builtin types and intrinsics (#7)
* feat: bake-in completion item for intrinsics * fix: fix codegen script * feat: make snippet syntax optional * feat: add builtin lookup table * feat: provide completions * chore: remove mention of unsupported channels and goroutines * feat: use "go:generate" for codegen * fix: use .txt for builtins to prevent build fails * chore: remove obsolete comment * fix: goimports * fix: skip detail generation for primitive types and literals * fix: goimports * fix: trim doc string * fix: use go/doc/comment as markdown generator * fix: avoid copy of *token.FileSet
- Loading branch information
Showing
17 changed files
with
1,438 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package builtin | ||
|
||
import ( | ||
"strings" | ||
|
||
"go.lsp.dev/protocol" | ||
) | ||
|
||
//go:generate go run ../../tools/codegen-builtins -src ../../tools/gendata/builtin.go.txt -dest ./builtin_gen.go -omit Type,Type1,IntegerType,FloatType,ComplexType | ||
|
||
// GetCompletions provides list of builtin symbols that has passed prefix in a name. | ||
func GetCompletions(prefix string) []protocol.CompletionItem { | ||
prefix = strings.TrimSpace(prefix) | ||
if prefix == "" { | ||
return nil | ||
} | ||
|
||
key, remainder := getBucketKey(prefix) | ||
bucket, ok := buckets[key] | ||
if !ok { | ||
return nil | ||
} | ||
|
||
if remainder == 0 { | ||
return bucket | ||
} | ||
|
||
// most buckets contain only single value | ||
if len(bucket) == 1 && strings.HasPrefix(bucket[0].Label, prefix) { | ||
return bucket | ||
} | ||
|
||
var items []protocol.CompletionItem | ||
for _, item := range bucket { | ||
// TODO: use fuzzy find? | ||
if strings.HasPrefix(item.Label, prefix) { | ||
items = append(items, item) | ||
} | ||
} | ||
|
||
return items | ||
} | ||
|
||
func getBucketKey(str string) (rune, int) { | ||
runes := []rune(str) | ||
return runes[0], len(runes) - 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.