aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2023-07-09 22:23:53 +0200
committerDanielGavin <danielgavin5@hotmail.com>2023-07-09 22:23:53 +0200
commit255ad5958026dc3a3116f621eaebd501b8b26a22 (patch)
tree23e8f3ae2e4406174202e22489af268617dfbf71 /src/server
parent86e5a54bfcf890338d6aad398d9f0f6410546929 (diff)
parent0af33a64747670545eaf31d1449586ff8f08b0f9 (diff)
Merge branch 'master' of https://github.com/DanielGavin/ols
Diffstat (limited to 'src/server')
-rw-r--r--src/server/collector.odin20
-rw-r--r--src/server/completion.odin75
-rw-r--r--src/server/methods.odin141
3 files changed, 144 insertions, 92 deletions
diff --git a/src/server/collector.odin b/src/server/collector.odin
index 21c6a52..1275275 100644
--- a/src/server/collector.odin
+++ b/src/server/collector.odin
@@ -184,11 +184,7 @@ collect_struct_fields :: proc(
types = types[:],
ranges = ranges[:],
usings = usings,
- poly = cast(^ast.Field_List)clone_type(
- struct_type.poly_params,
- collection.allocator,
- &collection.unique_strings,
- ),
+ poly = cast(^ast.Field_List)clone_type(struct_type.poly_params, collection.allocator, &collection.unique_strings),
}
return value
@@ -251,11 +247,7 @@ collect_union_fields :: proc(
value := SymbolUnionValue {
types = types[:],
- poly = cast(^ast.Field_List)clone_type(
- union_type.poly_params,
- collection.allocator,
- &collection.unique_strings,
- ),
+ poly = cast(^ast.Field_List)clone_type(union_type.poly_params, collection.allocator, &collection.unique_strings),
}
return value
@@ -456,6 +448,7 @@ collect_method :: proc(collection: ^SymbolCollection, symbol: Symbol) {
if ident, ok := v.expr.derived.(^ast.Ident); ok {
method.pkg = get_index_unique_string(collection, ident.name)
method.name = get_index_unique_string(collection, v.field.name)
+ log.error(method)
} else {
return
}
@@ -473,15 +466,8 @@ collect_method :: proc(collection: ^SymbolCollection, symbol: Symbol) {
symbols = &pkg.methods[method]
}
- if method.pkg != "$builtin" {
- //fmt.println(method)
- //fmt.println(symbol)
- }
-
append(symbols, symbol)
}
-
-
}
collect_objc :: proc(
diff --git a/src/server/completion.odin b/src/server/completion.odin
index 1bb2415..806f334 100644
--- a/src/server/completion.odin
+++ b/src/server/completion.odin
@@ -1613,81 +1613,6 @@ get_range_from_selection_start_to_dot :: proc(
return {}, false
}
-append_method_completion :: proc(
- ast_context: ^AstContext,
- symbol: Symbol,
- position_context: ^DocumentPositionContext,
- items: ^[dynamic]CompletionItem,
-) {
- if symbol.type != .Variable {
- return
- }
-
- selector: ^ast.Expr
-
- if position_context.selector_expr != nil {
- selector = position_context.selector_expr
- } else {
- selector = position_context.selector
- }
-
- for k, v in indexer.index.collection.packages {
- method := Method {
- name = symbol.name,
- pkg = symbol.pkg,
- }
- if symbols, ok := &v.methods[method]; ok {
- for symbol in symbols {
-
- resolve_unresolved_symbol(ast_context, &symbol)
- build_procedure_symbol_signature(&symbol)
-
- range, ok := get_range_from_selection_start_to_dot(position_context)
-
- if !ok {
- return
- }
-
- remove_range := common.Range {
- start = range.start,
- end = range.end,
- }
-
- remove_edit := TextEdit {
- range = remove_range,
- newText = "",
- }
-
- additionalTextEdits := make([]TextEdit, 1, context.temp_allocator)
- additionalTextEdits[0] = remove_edit
-
- item := CompletionItem {
- label = symbol.name,
- kind = cast(CompletionItemKind)symbol.type,
- detail = concatenate_symbol_information(
- ast_context,
- symbol,
- true,
- ),
- additionalTextEdits = additionalTextEdits,
- textEdit = TextEdit{
- newText = fmt.tprintf(
- "%v($0)",
- symbol.name,
- ),
- range = {start = range.end, end = range.end},
- },
- insertTextFormat = .Snippet,
- InsertTextMode = .adjustIndentation,
- documentation = symbol.doc,
- }
-
- append(items, item)
- }
- }
- }
-}
-
append_magic_map_completion :: proc(
position_context: ^DocumentPositionContext,
symbol: Symbol,
diff --git a/src/server/methods.odin b/src/server/methods.odin
new file mode 100644
index 0000000..60e7cd8
--- /dev/null
+++ b/src/server/methods.odin
@@ -0,0 +1,141 @@
+package server
+
+import "core:odin/parser"
+import "core:odin/ast"
+import "core:odin/tokenizer"
+import "core:fmt"
+import "core:log"
+import "core:strings"
+import path "core:path/slashpath"
+import "core:mem"
+import "core:strconv"
+import "core:path/filepath"
+import "core:sort"
+import "core:slice"
+import "core:os"
+
+
+import "shared:common"
+
+
+@(private)
+create_remove_edit :: proc(
+ position_context: ^DocumentPositionContext,
+) -> (
+ []TextEdit,
+ bool,
+) {
+ range, ok := get_range_from_selection_start_to_dot(position_context)
+
+ if !ok {
+ return {}, false
+ }
+
+ remove_range := common.Range {
+ start = range.start,
+ end = range.end,
+ }
+
+ remove_edit := TextEdit {
+ range = remove_range,
+ newText = "",
+ }
+
+ additionalTextEdits := make([]TextEdit, 1, context.temp_allocator)
+ additionalTextEdits[0] = remove_edit
+
+ return additionalTextEdits, true
+}
+
+append_method_completion :: proc(
+ ast_context: ^AstContext,
+ symbol: Symbol,
+ position_context: ^DocumentPositionContext,
+ items: ^[dynamic]CompletionItem,
+) {
+ if symbol.type != .Variable {
+ return
+ }
+
+ remove_edit, ok := create_remove_edit(position_context)
+
+ if !ok {
+ return
+ }
+
+ for k, v in indexer.index.collection.packages {
+ method := Method {
+ name = symbol.name,
+ pkg = symbol.pkg,
+ }
+ if symbols, ok := &v.methods[method]; ok {
+ for symbol in symbols {
+ resolve_unresolved_symbol(ast_context, &symbol)
+ build_procedure_symbol_signature(&symbol)
+
+ range, ok := get_range_from_selection_start_to_dot(
+ position_context,
+ )
+
+ if !ok {
+ return
+ }
+
+ value: SymbolProcedureValue
+ value, ok = symbol.value.(SymbolProcedureValue)
+
+ if !ok {
+ continue
+ }
+
+ first_arg: Symbol
+ first_arg, ok = resolve_type_expression(
+ ast_context,
+ value.arg_types[0].type,
+ )
+
+ if !ok {
+ continue
+ }
+
+ pointers_to_add := first_arg.pointers - symbol.pointers
+
+ if pointers_to_add != 1 {
+ pointers_to_add = 0
+ }
+
+ new_text := ""
+
+ if symbol.pkg != ast_context.document_package {
+ new_text = fmt.tprintf(
+ "%v.%v($0)",
+ path.base(symbol.pkg, false, ast_context.allocator),
+ symbol.name,
+ )
+ } else {
+ new_text = fmt.tprintf("%v($0)", symbol.name)
+ }
+
+ item := CompletionItem {
+ label = symbol.name,
+ kind = cast(CompletionItemKind)symbol.type,
+ detail = concatenate_symbol_information(
+ ast_context,
+ symbol,
+ true,
+ ),
+ additionalTextEdits = remove_edit,
+ textEdit = TextEdit{
+ newText = new_text,
+ range = {start = range.end, end = range.end},
+ },
+ insertTextFormat = .Snippet,
+ InsertTextMode = .adjustIndentation,
+ documentation = symbol.doc,
+ }
+
+ append(items, item)
+ }
+ }
+ }
+}