Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/server/ast.odin
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ get_file_doc :: proc(
get_field_docs_and_comments :: proc(
file: ast.File,
fields: []^ast.Expr,
allocator := context.temp_allocator,
allocator: mem.Allocator,
) -> (
[dynamic]^ast.Comment_Group,
[dynamic]^ast.Comment_Group,
Expand Down
98 changes: 39 additions & 59 deletions src/server/build.odin
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ skip_file :: proc(filename: string) -> bool {
return !is_bsd_variant(name_between)
}

if _, ok := platform_os[name_between]; ok {
if name_between in platform_os {
return name_between != common.config.profile.os
}
}
Expand Down Expand Up @@ -212,14 +212,7 @@ try_build_package :: proc(pkg_name: string) {
pkg = pkg,
}

ok = parser.parse_file(&p, &file)

if !ok {
if !strings.contains(fullpath, "builtin.odin") && !strings.contains(fullpath, "intrinsics.odin") {
log.errorf("error in parse file for indexing %v", fullpath)
}
continue
}
parse_file(&p, &file, indexer.index.collection.allocator) or_continue

uri := common.create_uri(fullpath, context.allocator)

Expand All @@ -234,41 +227,56 @@ try_build_package :: proc(pkg_name: string) {
}
}


remove_index_file :: proc(uri: common.Uri) -> common.Error {
ok: bool

fullpath := uri.path

when ODIN_OS == .Windows {
fullpath, _ = filepath.to_slash(fullpath, context.temp_allocator)
parse_file :: proc(
p: ^parser.Parser,
file: ^ast.File,
allocator: mem.Allocator,
loc := #caller_location,
) -> (ok: bool) {
context.allocator = allocator
ok = parser.parse_file(p, file)
if !ok &&
!strings.ends_with(file.fullpath, "builtin.odin") &&
!strings.ends_with(file.fullpath, "intrinsics.odin") {
log.errorf("parse_file failed for %s", file.fullpath, location=loc)
}
return ok
}

corrected_uri := common.create_uri(fullpath, context.temp_allocator)
remove_file_symbols :: proc(uri: common.Uri) {

for k, &v in indexer.index.collection.packages {
for k2, v2 in v.symbols {
if strings.equal_fold(corrected_uri.uri, v2.uri) {
free_symbol(v2, indexer.index.collection.allocator)
delete_key(&v.symbols, k2)
for _, &pkg in indexer.index.collection.packages {
for symbol_key, symbol in pkg.symbols {
if strings.equal_fold(uri.uri, symbol.uri) {
free_symbol(symbol, indexer.index.collection.allocator)
delete_key(&pkg.symbols, symbol_key)
}
}

for method, &symbols in v.methods {
for i := len(symbols) - 1; i >= 0; i -= 1 {
#no_bounds_check symbol := symbols[i]
if strings.equal_fold(corrected_uri.uri, symbol.uri) {
unordered_remove(&symbols, i)
for method, &symbols in pkg.methods {
#reverse for symbol, i in symbols {
if strings.equal_fold(uri.uri, symbol.uri) {
unordered_remove(&symbols, len(symbols) - 1 - i)
}
}
}
}
}

remove_index_file :: proc(uri: common.Uri) -> common.Error {

fullpath := uri.path
when ODIN_OS == .Windows {
fullpath, _ = filepath.to_slash(fullpath, context.temp_allocator)
}

corrected_uri := common.create_uri(fullpath, context.temp_allocator)
remove_file_symbols(corrected_uri)

return .None
}

index_file :: proc(uri: common.Uri, text: string) -> common.Error {
ok: bool

fullpath := uri.path

Expand Down Expand Up @@ -300,39 +308,11 @@ index_file :: proc(uri: common.Uri, text: string) -> common.Error {
pkg = pkg,
}

{
allocator := context.allocator
context.allocator = context.temp_allocator
defer context.allocator = allocator

ok = parser.parse_file(&p, &file)

if !ok {
if !strings.contains(fullpath, "builtin.odin") && !strings.contains(fullpath, "intrinsics.odin") {
log.errorf("error in parse file for indexing %v", fullpath)
}
}
}
parse_file(&p, &file, indexer.index.collection.allocator)

corrected_uri := common.create_uri(fullpath, context.temp_allocator)

for k, &v in indexer.index.collection.packages {
for k2, v2 in v.symbols {
if corrected_uri.uri == v2.uri {
free_symbol(v2, indexer.index.collection.allocator)
delete_key(&v.symbols, k2)
}
}

for method, &symbols in v.methods {
for i := len(symbols) - 1; i >= 0; i -= 1 {
#no_bounds_check symbol := symbols[i]
if corrected_uri.uri == symbol.uri {
unordered_remove(&symbols, i)
}
}
}
}
remove_file_symbols(corrected_uri)

if ret := collect_symbols(&indexer.index.collection, file, corrected_uri.uri); ret != .None {
log.errorf("failed to collect symbols on save %v", ret)
Expand Down
56 changes: 56 additions & 0 deletions src/server/clone.odin
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,62 @@ new_type :: proc($T: typeid, pos, end: tokenizer.Pos, allocator: mem.Allocator)
return n
}

/*
Recursively clone all strings the ast node to collection's unique string map.

**Note:** This mutates the original node to point to the deduplicated strings.
*/
collection_clone_node_strings :: proc(collection: ^SymbolCollection, node: ^ast.Node) {

if node == nil || collection == nil {
return
}

visitor := ast.Visitor{
data = collection,
visit = proc(visitor: ^ast.Visitor, node: ^ast.Node) -> ^ast.Visitor {
if node == nil {
return nil
}

collection := cast(^SymbolCollection)visitor.data

// Clone position file names
if node.pos.file != "" {
node.pos.file = get_index_unique_string(collection, node.pos.file)
}
if node.end.file != "" {
node.end.file = get_index_unique_string(collection, node.end.file)
}

// Clone strings in specific nodes
#partial switch n in node.derived {
case ^ast.Ident:
n.name = get_index_unique_string(collection, n.name)
case ^ast.Basic_Lit:
n.tok.text = get_index_unique_string(collection, n.tok.text)
case ^ast.Basic_Directive:
n.name = get_index_unique_string(collection, n.name)
case ^ast.Implicit:
n.tok.text = get_index_unique_string(collection, n.tok.text)
case ^ast.Unary_Expr:
n.op.text = get_index_unique_string(collection, n.op.text)
case ^ast.Binary_Expr:
n.op.text = get_index_unique_string(collection, n.op.text)
case ^ast.Comment_Group:
for &token in n.list {
token.text = get_index_unique_string(collection, token.text)
token.pos.file = get_index_unique_string(collection, token.pos.file)
}
}

return visitor
},
}

ast.walk(&visitor, node)
}

clone_type :: proc {
clone_node,
clone_expr,
Expand Down
Loading