aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2022-03-04 19:22:33 +0100
committerDaniel Gavin <danielgavin5@hotmail.com>2022-03-04 19:22:33 +0100
commit2d9f5709d74992e0cd485099a5a8cdf12178e80d (patch)
treeaebd707471ee0d6a62334bfd69f5681299f692cb /src
parent75ab88b2c81c164b851c4e064f4da1c11b2a5679 (diff)
Add support for builtin symbols.
Diffstat (limited to 'src')
-rw-r--r--src/analysis/analysis.odin3
-rw-r--r--src/common/ast.odin10
-rw-r--r--src/index/build.odin1
-rw-r--r--src/index/collector.odin6
-rw-r--r--src/index/memory_index.odin3
-rw-r--r--src/server/completion.odin1
6 files changed, 17 insertions, 7 deletions
diff --git a/src/analysis/analysis.odin b/src/analysis/analysis.odin
index 400bde6..b7be73c 100644
--- a/src/analysis/analysis.odin
+++ b/src/analysis/analysis.odin
@@ -1346,6 +1346,9 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i
//If we are resolving a symbol that is in the document package, then we'll check the builtin packages.
if ast_context.current_package == ast_context.document_package {
+ if symbol, ok := index.lookup(node.name, "$builtin"); ok {
+ return resolve_symbol_return(ast_context, symbol)
+ }
for built in index.indexer.builtin_packages {
if symbol, ok := index.lookup(node.name, built); ok {
return resolve_symbol_return(ast_context, symbol)
diff --git a/src/common/ast.odin b/src/common/ast.odin
index 669b44a..7a32cde 100644
--- a/src/common/ast.odin
+++ b/src/common/ast.odin
@@ -73,9 +73,9 @@ GlobalExpr :: struct {
deprecated: bool,
file_private: bool,
package_private: bool,
+ builtin: bool,
}
-
unwrap_pointer :: proc(expr: ^ast.Expr) -> (ast.Ident, bool) {
expr := expr
for expr != nil {
@@ -99,10 +99,10 @@ unwrap_pointer :: proc(expr: ^ast.Expr) -> (ast.Ident, bool) {
collect_value_decl :: proc(exprs: ^[dynamic]GlobalExpr, file: ast.File, stmt: ^ast.Node, skip_private: bool) {
if value_decl, ok := stmt.derived.(^ast.Value_Decl); ok {
-
is_deprecated := false
is_private_file := false
is_package_file := false
+ is_builtin := false
for attribute in value_decl.attributes {
for elem in attribute.elems {
@@ -118,14 +118,14 @@ collect_value_decl :: proc(exprs: ^[dynamic]GlobalExpr, file: ast.File, stmt: ^a
is_package_file = true
}
}
- case "deprecated":
- is_deprecated = true
}
}
} else if ident, ok := elem.derived.(^ast.Ident); ok {
switch ident.name {
case "deprecated":
is_deprecated = true
+ case "builtin":
+ is_builtin = true
}
}
}
@@ -146,6 +146,7 @@ collect_value_decl :: proc(exprs: ^[dynamic]GlobalExpr, file: ast.File, stmt: ^a
docs = value_decl.docs,
attributes = value_decl.attributes[:],
deprecated = is_deprecated,
+ builtin = is_builtin,
})
} else {
if len(value_decl.values) > i {
@@ -156,6 +157,7 @@ collect_value_decl :: proc(exprs: ^[dynamic]GlobalExpr, file: ast.File, stmt: ^a
docs = value_decl.docs,
attributes = value_decl.attributes[:],
deprecated = is_deprecated,
+ builtin = is_builtin,
})
}
}
diff --git a/src/index/build.odin b/src/index/build.odin
index a7944f0..8acb052 100644
--- a/src/index/build.odin
+++ b/src/index/build.odin
@@ -113,6 +113,7 @@ build_static_index :: proc(allocator := context.allocator, config: ^common.Confi
p := parser.Parser {
err = log_error_handler,
warn = log_warning_handler,
+ flags = {.Optional_Semicolons},
}
//have to cheat the parser since it really wants to parse an entire package with the new changes...
diff --git a/src/index/collector.odin b/src/index/collector.odin
index 495e2a3..c527873 100644
--- a/src/index/collector.odin
+++ b/src/index/collector.odin
@@ -359,6 +359,12 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri
symbol.type = token_type
symbol.doc = common.get_doc(expr.docs, collection.allocator)
+ if expr.builtin {
+ symbol.pkg = "$builtin"
+ } else {
+ symbol.pkg = get_index_unique_string(collection, directory)
+ }
+
if expr.deprecated {
symbol.flags |= {.Deprecated}
}
diff --git a/src/index/memory_index.odin b/src/index/memory_index.odin
index d4e7e6e..5146bf8 100644
--- a/src/index/memory_index.odin
+++ b/src/index/memory_index.odin
@@ -19,7 +19,6 @@ MemoryIndex :: struct {
}
make_memory_index :: proc(collection: SymbolCollection) -> MemoryIndex {
-
return MemoryIndex {
collection = collection,
}
@@ -31,7 +30,6 @@ memory_index_lookup :: proc(index: ^MemoryIndex, name: string, pkg: string) -> (
}
memory_index_fuzzy_search :: proc(index: ^MemoryIndex, name: string, pkgs: []string) -> ([]FuzzyResult, bool) {
-
symbols := make([dynamic]FuzzyResult, 0, context.temp_allocator)
fuzzy_matcher := common.make_fuzzy_matcher(name)
@@ -64,7 +62,6 @@ memory_index_fuzzy_search :: proc(index: ^MemoryIndex, name: string, pkgs: []str
}
exists_in_scope :: proc(symbol_scope: string, scope: []string) -> bool {
-
for s in scope {
if strings.compare(symbol_scope, s) == 0 {
return true
diff --git a/src/server/completion.odin b/src/server/completion.odin
index 78697ac..ca731c6 100644
--- a/src/server/completion.odin
+++ b/src/server/completion.odin
@@ -834,6 +834,7 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co
}
append(&pkgs, ast_context.document_package)
+ append(&pkgs, "$builtin")
if results, ok := index.fuzzy_search(lookup, pkgs[:]); ok {
for r in results {