diff options
| -rw-r--r-- | build.bat | 8 | ||||
| -rw-r--r-- | src/index/indexer.odin | 12 | ||||
| -rw-r--r-- | src/main.odin | 6 | ||||
| -rw-r--r-- | src/server/analysis.odin | 82 | ||||
| -rw-r--r-- | src/server/requests.odin | 11 |
5 files changed, 102 insertions, 17 deletions
@@ -2,9 +2,15 @@ rem odin run tests\ -show-timings -llvm-api -collection:shared=src -microarch:native -out:test + rem odin build tests\ -show-timings -collection:shared=src -microarch:native -out:test -debug -odin build src\ -llvm-api -show-timings -microarch:native -collection:shared=src -out:ols -debug +rem odin build src\ -show-timings -microarch:native -collection:shared=src -out:ols -debug + + +rem odin build src\ -llvm-api -show-timings -microarch:native -collection:shared=src -out:ols -debug + +odin build src\ -show-timings -microarch:native -collection:shared=src -out:ols -opt:3 diff --git a/src/index/indexer.odin b/src/index/indexer.odin index 073d32d..e04febd 100644 --- a/src/index/indexer.odin +++ b/src/index/indexer.odin @@ -39,6 +39,7 @@ import "core:sort" Indexer :: struct { + built_in_packages: [dynamic] string, static_index: MemoryIndex, }; @@ -57,11 +58,14 @@ lookup :: proc(name: string, pkg: string, loc := #caller_location) -> (Symbol, b return symbol, true; } - if symbol, ok := memory_index_lookup(&indexer.static_index, name, "builtin"); ok { - log.infof("lookup name: %v pkg: %v, symbol %v location %v", name, pkg, symbol, loc); - return symbol, true; - } + for built in indexer.built_in_packages { + if symbol, ok := memory_index_lookup(&indexer.static_index, name, built); ok { + log.infof("lookup name: %v pkg: %v, symbol %v location %v", name, pkg, symbol, loc); + return symbol, true; + } + + } log.infof("lookup failed name: %v pkg: %v location %v", name, pkg, loc); return {}, false; diff --git a/src/main.odin b/src/main.odin index 62c5982..d96c6e2 100644 --- a/src/main.odin +++ b/src/main.odin @@ -33,7 +33,7 @@ os_write :: proc(handle: rawptr, data: [] byte) -> (int, int) run :: proc(reader: ^server.Reader, writer: ^server.Writer) { config: common.Config; - + config.debug_single_thread = false; //tracking_allocator := common.memleak_allocator(true); //context.allocator = tracking_allocator; @@ -104,12 +104,12 @@ main :: proc() { init_global_temporary_allocator(mem.megabytes(200)); - //context.logger = log.Logger{nil, nil, log.Level.Debug, nil}; //have to set the procedure to nil to avoid calling tprintf... + context.logger = log.Logger{nil, nil, log.Level.Debug, nil}; //have to set the procedure to nil to avoid calling tprintf... //fd, err := os.open("C:/Users/danie/OneDrive/Desktop/Computer_Science/ols/log.txt", os.O_RDWR|os.O_CREATE|os.O_TRUNC ); //context.logger = log.create_file_logger(fd); - context.logger = server.create_lsp_logger(&writer); + //context.logger = server.create_lsp_logger(&writer); run(&reader, &writer); } diff --git a/src/server/analysis.odin b/src/server/analysis.odin index cf68cd5..49a53ac 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -11,12 +11,14 @@ import "core:mem" import "core:strconv" import "core:path/filepath" import "core:sort" +import "core:slice" import "shared:common" import "shared:index" /* TODO(replace all of the possible ast walking with the new odin visitor function) + TODO(improve the current_package logic, kinda confusing switching between different packages with selectors) */ bool_lit := "bool"; @@ -300,7 +302,7 @@ resolve_generic_function_symbol :: proc(ast_context: ^AstContext, params: []^ast for name in param.names { - if len(call_expr.args) >= i { + if len(call_expr.args) <= i { break; } @@ -515,6 +517,8 @@ resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (i return resolve_basic_lit(ast_context, v); case Type_Cast: return resolve_type_expression(ast_context, v.expr); + case Auto_Cast: + return resolve_type_expression(ast_context, v.expr); case Unary_Expr: return resolve_type_expression(ast_context, v.expr); case Deref_Expr: @@ -525,6 +529,12 @@ resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (i return resolve_type_expression(ast_context, v.expr); case Tag_Expr: return resolve_type_expression(ast_context, v.expr); + case Ellipsis: + return resolve_type_expression(ast_context, v.expr); + case Implicit: + ident := index.new_type(Ident, v.node.pos, v.node.end, context.temp_allocator); + ident.name = v.tok.text; + return resolve_type_identifier(ast_context, ident^); case Type_Assertion: resolve_type_expression(ast_context, v.type); case Proc_Lit: @@ -768,6 +778,11 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i } + //if there are more of these variables that hard builtin, move them to the indexer + else if node.name == "context" { + log.info("found context"); + return index.lookup("Context", ast_context.current_package); + } //keywords else if v, ok := common.keyword_map[node.name]; ok { @@ -1214,10 +1229,10 @@ get_locals_value_decl :: proc(file: ast.File, value_decl: ast.Value_Decl, ast_co get_generic_assignment(file, value, ast_context, &results); } - for name, i in value_decl.names { if i < len(results) { str := common.get_ast_node_string(name, file.src); + ast_context.in_package[str] = get_package_from_node(results[i]); ast_context.locals[str] = results[i]; ast_context.variables[str] = value_decl.is_mutable; } @@ -1261,6 +1276,8 @@ get_locals_stmt :: proc(file: ast.File, stmt: ^ast.Stmt, ast_context: ^AstContex for stmt in v.stmts { get_locals_stmt(file, stmt, ast_context, document_position); } + case Proc_Lit: + get_locals_stmt(file, v.body, ast_context, document_position); case Assign_Stmt: get_locals_assign_stmt(file, v, ast_context); case Using_Stmt: @@ -1554,6 +1571,10 @@ concatenate_symbols_information :: proc(ast_context: ^AstContext, symbol: index. } + else if symbol.type == .Package { + return symbol.name; + } + else { if symbol.signature != "" { return strings.concatenate({pkg, "::", symbol.name, ": ", symbol.signature}, context.temp_allocator); @@ -1774,8 +1795,11 @@ get_completion_list :: proc(document: ^Document, position: common.Position) -> ( } else { - log.errorf("Failed to resolve field: %v", name); - return list, true; + //just give some generic symbol with name. + symbol: index.Symbol; + symbol.name = name; + symbol.type = .Field; + append(&symbols, symbol); } } @@ -1831,8 +1855,10 @@ get_completion_list :: proc(document: ^Document, position: common.Position) -> ( } else { - log.errorf("Failed to resolve field: %v", name); - return list, true; + symbol: index.Symbol; + symbol.name = name; + symbol.type = .Field; + append(&symbols, symbol); } } } @@ -1893,7 +1919,6 @@ get_completion_list :: proc(document: ^Document, position: common.Position) -> ( lookup = ident.name; } - pkgs := make([dynamic] string, context.temp_allocator); usings := get_using_packages(&ast_context); @@ -1914,6 +1939,32 @@ get_completion_list :: proc(document: ^Document, position: common.Position) -> ( matcher := common.make_fuzzy_matcher(lookup); + global: for k, v in ast_context.globals { + + //combined is sorted and should do binary search instead. + for result in combined { + if result.symbol.name == k { + continue global; + } + } + + ast_context.use_locals = true; + ast_context.use_globals = true; + ast_context.current_package = ast_context.document_package; + + ident := index.new_type(ast.Ident, tokenizer.Pos {}, tokenizer.Pos {}, context.temp_allocator); + ident.name = k; + + if symbol, ok := resolve_type_identifier(&ast_context, ident^); ok { + symbol.name = ident.name; + + if score, ok := common.fuzzy_match(matcher, symbol.name); ok { + append(&combined, CombinedResult { score = score * 1.1, symbol = symbol, variable = ident }); + } + + } + } + for k, v in ast_context.locals { ast_context.use_locals = true; @@ -1933,6 +1984,21 @@ get_completion_list :: proc(document: ^Document, position: common.Position) -> ( } } + + for pkg in ast_context.imports { + + symbol: index.Symbol; + + symbol.name = pkg.base; + symbol.type = .Package; + + if score, ok := common.fuzzy_match(matcher, symbol.name); ok { + append(&combined, CombinedResult { score = score * 1.1, symbol = symbol }); + } + } + + + sort.sort(combined_sort_interface(&combined)); //hard code for now @@ -1948,7 +2014,7 @@ get_completion_list :: proc(document: ^Document, position: common.Position) -> ( }; if result.variable != nil { - + //ERROR crash on definition if ok := resolve_ident_is_variable(&ast_context, result.variable^); ok { item.kind = .Variable; } diff --git a/src/server/requests.odin b/src/server/requests.odin index ff540c7..66d3dbf 100644 --- a/src/server/requests.odin +++ b/src/server/requests.odin @@ -112,7 +112,7 @@ read_and_parse_header :: proc(reader: ^Reader) -> (Header, bool) { } header_name := message[0:index]; - header_value := message[len(header_name) + 2 : len(message)-1]; + header_value := message[len(header_name) + 2 : len(message)-2]; if strings.compare(header_name, "Content-Length") == 0 { @@ -492,6 +492,15 @@ request_initialize :: proc(task: ^common.Task) { index.build_static_index(context.allocator, config); + /* + Add the builtin and runtime package + */ + + if core, ok := config.collections["core"]; ok { + append(&index.indexer.built_in_packages, path.join(core, "builtin")); + append(&index.indexer.built_in_packages, path.join(core, "runtime")); + } + log.info("Finished indexing"); } |