diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-04-09 18:56:16 +0200 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-04-09 18:56:16 +0200 |
| commit | 4d0d079b4b79ce5730d8c2ee8694652a3f73049f (patch) | |
| tree | bae34f55c8505b7ddd2891d474e419ebadd123fe /src | |
| parent | b0cd697758c2ea6661ca41fa76fcd2a344bf87b9 (diff) | |
prepare to merge analysis with index
Diffstat (limited to 'src')
| -rw-r--r-- | src/index/build.odin | 49 | ||||
| -rw-r--r-- | src/index/collector.odin | 1 | ||||
| -rw-r--r-- | src/index/file_index.odin | 1 | ||||
| -rw-r--r-- | src/index/references.odin | 39 | ||||
| -rw-r--r-- | src/index/symbol.odin | 1 | ||||
| -rw-r--r-- | src/odin/printer/document.odin | 22 | ||||
| -rw-r--r-- | src/odin/printer/visit.odin | 49 | ||||
| -rw-r--r-- | src/server/writer.odin | 1 |
8 files changed, 128 insertions, 35 deletions
diff --git a/src/index/build.odin b/src/index/build.odin index 21b48d5..f74f02f 100644 --- a/src/index/build.odin +++ b/src/index/build.odin @@ -116,8 +116,6 @@ build_static_index :: proc(allocator := context.allocator, config: ^common.Confi flags = {.Optional_Semicolons}, } - //have to cheat the parser since it really wants to parse an entire package with the new changes... - dir := filepath.base(filepath.dir(fullpath, context.allocator)) pkg := new(ast.Package) @@ -147,6 +145,53 @@ build_static_index :: proc(allocator := context.allocator, config: ^common.Confi collect_symbols(&symbol_collection, file, uri.uri) free_all(context.allocator) + } + + //afterwards, I have to go through the files again to find all the references. Better to reload individually the files again to ensure we don't use too much memory. + + for fullpath in files { + data, ok := os.read_entire_file(fullpath, context.allocator) + + if !ok { + log.errorf("failed to read entire file for indexing %v", fullpath) + continue + } + + p := parser.Parser { + err = log_error_handler, + warn = log_warning_handler, + flags = {.Optional_Semicolons}, + } + + dir := filepath.base(filepath.dir(fullpath, context.allocator)) + + pkg := new(ast.Package) + pkg.kind = .Normal + pkg.fullpath = fullpath + pkg.name = dir + + if dir == "runtime" { + pkg.kind = .Runtime + } + + file := ast.File { + fullpath = fullpath, + src = string(data), + pkg = pkg, + } + + ok = parser.parse_file(&p, &file) + + if !ok { + log.info(pkg) + log.errorf("error in parse file for indexing %v", fullpath) + } + + uri := common.create_uri(fullpath, context.allocator) + + //collect_references(&symbol_collection, file, uri.uri) + + free_all(context.allocator) delete(fullpath, allocator) } diff --git a/src/index/collector.odin b/src/index/collector.odin index f9f3389..c915689 100644 --- a/src/index/collector.odin +++ b/src/index/collector.odin @@ -16,6 +16,7 @@ SymbolCollection :: struct { allocator: mem.Allocator, config: ^common.Config, packages: map[string]map[string]Symbol, + //references: map[string]map[string]Reference, unique_strings: map[string]string, //store all our strings as unique strings and reference them to save memory. } diff --git a/src/index/file_index.odin b/src/index/file_index.odin deleted file mode 100644 index 60a0228..0000000 --- a/src/index/file_index.odin +++ /dev/null @@ -1 +0,0 @@ -package index diff --git a/src/index/references.odin b/src/index/references.odin new file mode 100644 index 0000000..6613925 --- /dev/null +++ b/src/index/references.odin @@ -0,0 +1,39 @@ +package index + +/* +import "shared:common" +import "shared:analysis" + +import "core:strings" +import "core:odin/ast" + + +Reference :: struct { + identifiers: [dynamic]^ast.Ident, + selectors: [dynamic]^ast.Selector_Expr, +} + +collect_references :: proc(collection: ^SymbolCollection, file: ast.File, uri: string) -> common.Error { + document := common.Document { + ast = file, + + } + + uri, ok := common.parse_uri(uri, context.temp_allocator) + + if !ok { + return .ParseError + } + + when ODIN_OS == .Windows { + document.package_name = strings.to_lower(path.dir(document.uri.path, context.temp_allocator)) + } else { + document.package_name = path.dir(document.uri.path) + } + + + return {} + +} +*/ + diff --git a/src/index/symbol.odin b/src/index/symbol.odin index 312264a..56336cc 100644 --- a/src/index/symbol.odin +++ b/src/index/symbol.odin @@ -123,7 +123,6 @@ Symbol :: struct { signature: string, //type signature type: SymbolType, value: SymbolValue, - references: []common.Range, //all the places in the project that it's being referenced pointers: int, //how many `^` are applied to the symbol flags: SymbolFlags, } diff --git a/src/odin/printer/document.odin b/src/odin/printer/document.odin index 0ae8e2c..1f104a3 100644 --- a/src/odin/printer/document.odin +++ b/src/odin/printer/document.odin @@ -44,8 +44,7 @@ Document_If_Break :: struct { Document_Group :: struct { document: ^Document, - fill: bool, - fit: bool, + mode: Document_Group_Mode, } Document_Cons :: struct { @@ -108,7 +107,16 @@ enforce_fit :: proc(fitted_document: ^Document, allocator := context.allocator) document := new(Document, allocator) document^ = Document_Group { document = fitted_document, - fit = true, + mode = .Fit, + } + return document +} + +enforce_break :: proc(fitted_document: ^Document, allocator := context.allocator) -> ^Document { + document := new(Document, allocator) + document^ = Document_Group { + document = fitted_document, + mode = .Break, } return document } @@ -158,7 +166,7 @@ fill_group :: proc(grouped_document: ^Document, allocator := context.allocator) document := new(Document, allocator) document^ = Document_Group { document = grouped_document, - fill = true, + mode = .Fill, } return document } @@ -338,12 +346,12 @@ format :: proc(width: int, list: ^[dynamic]Tuple, builder: ^strings.Builder, p: if data.mode == .Fit { append(list, Tuple {indentation = data.indentation, mode = .Fit, document = v.document, alignment = data.alignment}) } - else if fits(width-consumed, &l, &fits_consumed) && !v.fit { + else if fits(width-consumed, &l, &fits_consumed) && v.mode != .Break { append(list, Tuple {indentation = data.indentation, mode = .Flat, document = v.document, alignment = data.alignment}) } else { - if v.fill { + if v.mode == .Fill { append(list, Tuple {indentation = data.indentation, mode = .Fill, document = v.document, alignment = data.alignment}) - } else if v.fit { + } else if v.mode == .Fit { append(list, Tuple {indentation = data.indentation, mode = .Fit, document = v.document, alignment = data.alignment}) } else { append(list, Tuple {indentation = data.indentation, mode = .Break, document = v.document, alignment = data.alignment}) diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index 222bb0b..2f45dc1 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -1157,9 +1157,20 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, called_from: Expr_Called_Type = case ^Call_Expr: document := visit_expr(p, v.expr) document = cons(document, text("(")) - document = cons(document, nest(p.indentation_count, cons(break_with(""), visit_call_exprs(p, v.args, v.ellipsis.kind == .Ellipsis)))) + + contains_comments := contains_comments_in_range(p, v.open, v.close) + + document = cons(document, nest(p.indentation_count, cons(break_with(""), visit_call_exprs(p, v)))) document = cons(document, cons(break_with(""), text(")"))) - return group(document) + + //We enforce a break if comments exists inside the call args + if contains_comments { + document = enforce_break(document) + } else { + document = group(document) + } + + return document case ^Typeid_Type: document := text("typeid") @@ -1494,20 +1505,28 @@ visit_binary_expr :: proc(p: ^Printer, binary: ast.Binary_Expr) -> ^Document { } @(private) -visit_call_exprs :: proc(p: ^Printer, list: []^ast.Expr, ellipsis := false) -> ^Document { +visit_call_exprs :: proc(p: ^Printer, call_expr: ^ast.Call_Expr) -> ^Document { document := empty() - for expr, i in list { - if i == len(list) - 1 && ellipsis { + ellipsis := call_expr.ellipsis.kind == .Ellipsis + + for expr, i in call_expr.args { + if i == len(call_expr.args) - 1 && ellipsis { document = cons(document, text("..")) } document = cons(document, group(visit_expr(p, expr))) - if i != len(list) - 1 { + if i != len(call_expr.args) - 1 { document = cons(document, text(",")) + + //need to look for comments before we write the comma with break + comments, _ := visit_comments(p, call_expr.args[i+1].pos) + + document = cons(document, comments) document = cons(document, break_with_space()) } else { - document = cons(document, if_break(",")) + comments, _ := visit_comments(p, call_expr.close) + document = cons(document, cons(if_break(","), comments)) } } @@ -1516,22 +1535,6 @@ visit_call_exprs :: proc(p: ^Printer, list: []^ast.Expr, ellipsis := false) -> ^ @(private) visit_field_flag :: proc(p: ^Printer, flags: ast.Field_Flags) -> ^Document { - - /* - Ellipsis, - Using, - No_Alias, - C_Vararg, - Auto_Cast, - Any_Int, - - Results, - Tags, - Default_Parameters, - Typeid_Token, - */ - - document := empty() if .Auto_Cast in flags { diff --git a/src/server/writer.odin b/src/server/writer.odin index ae26bee..bbd0cac 100644 --- a/src/server/writer.odin +++ b/src/server/writer.odin @@ -20,7 +20,6 @@ make_writer :: proc(writer_fn: WriterFn, writer_context: rawptr) -> Writer { } write_sized :: proc(writer: ^Writer, data: []byte) -> bool { - sync.mutex_lock(&writer.writer_mutex) defer sync.mutex_unlock(&writer.writer_mutex) |