diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2021-03-12 00:57:52 +0100 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2021-03-12 00:57:52 +0100 |
| commit | 1004c5c127c0eff5e2b90b235a0c47dc1aa4da10 (patch) | |
| tree | 42ca929ed02e93e08cad7c7bd965accf7d9cf198 /src/server | |
| parent | 575058d8ee68eed9e4eadb69202420b472f38e3c (diff) | |
fixed some crash bugs + add union completion + getting ready for format
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/analysis.odin | 12 | ||||
| -rw-r--r-- | src/server/completion.odin | 11 | ||||
| -rw-r--r-- | src/server/format.odin | 56 | ||||
| -rw-r--r-- | src/server/requests.odin | 57 | ||||
| -rw-r--r-- | src/server/types.odin | 3 |
5 files changed, 128 insertions, 11 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index d4e1728..01fe736 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -744,14 +744,9 @@ get_local :: proc(ast_context: ^AstContext, offset: int, name: string) -> ^ast.E for i := len(local_stack)-1; i >= 0; i -= 1 { if local_stack[i].offset <= offset { - log.errorf(" found %v %v", local_stack[i].offset, offset); return local_stack[max(0, i - previous)].expr; } - else { - log.errorf("not found %v %v", local_stack[i].offset, offset); - } - } } @@ -1607,7 +1602,6 @@ get_locals_assign_stmt :: proc(file: ast.File, stmt: ast.Assign_Stmt, ast_contex if ident, ok := lhs.derived.(ast.Ident); ok { store_local(ast_context, results[i], ident.pos.offset, ident.name); ast_context.variables[ident.name] = true; - log.errorf("store %v ", ident.name); } } @@ -2065,11 +2059,11 @@ get_signature_information :: proc(document: ^Document, position: common.Position position_context, ok := get_document_position_context(document, position, .SignatureHelp); if !ok { - return signature_help, false; + return signature_help, true; } if position_context.call == nil { - return signature_help, false; + return signature_help, true; } get_globals(document.ast, &ast_context); @@ -2350,7 +2344,7 @@ fallback_position_context_signature :: proc(document: ^Document, position: commo end: int; start: int; first_paren: bool; - i := position_context.position; + i := position_context.position-1; for i > 0 { diff --git a/src/server/completion.odin b/src/server/completion.odin index 07fea84..7acbadf 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -263,6 +263,17 @@ get_selector_completion :: proc(ast_context: ^AstContext, position_context: ^Doc #partial switch v in selector.value { + case index.SymbolUnionValue: + list.isIncomplete = false; + + for name in v.names { + symbol: index.Symbol; + symbol.name = fmt.aprintf("(%v)", name); + symbol.pkg = selector.name; + symbol.type = .EnumMember; + append(&symbols, symbol); + } + case index.SymbolEnumValue: list.isIncomplete = false; diff --git a/src/server/format.odin b/src/server/format.odin new file mode 100644 index 0000000..46d21e2 --- /dev/null +++ b/src/server/format.odin @@ -0,0 +1,56 @@ +package server + +import "shared:common" + +import "core:odin/printer" + +FormattingOptions :: struct { + tabSize: uint, + insertSpaces: bool, //tabs or spaces + trimTrailingWhitespace: bool, + insertFinalNewline: bool, + trimFinalNewlines: bool, +} + +DocumentFormattingParams :: struct { + textDocument: TextDocumentIdentifier, + options: FormattingOptions, +} + +TextEdit :: struct { + range: common.Range, + newText: string, +} + +get_complete_format :: proc(document: ^Document) -> ([] TextEdit, bool) { + + /* + prnt := printer.make_printer(printer.default_style, context.temp_allocator); + + printer.print_file(&prnt, &document.ast); + + end_line := document.ast.decls[len(document.ast.decls)-1].end.line; + + edit := TextEdit { + newText = printer.to_string(prnt), + range = { + start = { + character = 0, + line = 0, + }, + end = { + character = 1, + line = end_line + 1, + } + } + }; + + edits := make([dynamic] TextEdit, context.temp_allocator); + + append(&edits, edit); + + return edits[:], true; + */ + + return {}, false; +}
\ No newline at end of file diff --git a/src/server/requests.odin b/src/server/requests.odin index d4e3cb3..71dba0c 100644 --- a/src/server/requests.odin +++ b/src/server/requests.odin @@ -40,6 +40,7 @@ RequestType :: enum { DocumentSymbol, SemanticTokensFull, SemanticTokensRange, + FormatDocument, Hover, CancelRequest, }; @@ -191,7 +192,8 @@ request_map : map [string] RequestType = "textDocument/semanticTokens/full" = .SemanticTokensFull, "textDocument/semanticTokens/range" = .SemanticTokensRange, "textDocument/hover" = .Hover, - "$/cancelRequest" = .CancelRequest }; + "$/cancelRequest" = .CancelRequest, + "textDocument/formatting" = .FormatDocument }; handle_error :: proc(err: common.Error, id: RequestId, writer: ^Writer) { @@ -290,6 +292,8 @@ handle_request :: proc(request: json.Value, config: ^common.Config, writer: ^Wri case .Hover: task_proc = request_hover; case .CancelRequest: + case .FormatDocument: + task_proc = request_format_document; } task := common.Task { @@ -310,7 +314,7 @@ handle_request :: proc(request: json.Value, config: ^common.Config, writer: ^Wri } case .Initialize, .Initialized: task_proc(&task); - case .Completion, .Definition, .Hover: + case .Completion, .Definition, .Hover, .FormatDocument: uri := root["params"].value.(json.Object)["textDocument"].value.(json.Object)["uri"].value.(json.String); @@ -415,6 +419,7 @@ request_initialize :: proc(task: ^common.Task) { enable_document_symbols: bool; enable_hover: bool; + enable_format: bool; if len(config.workspace_folders) > 0 { @@ -434,6 +439,7 @@ request_initialize :: proc(task: ^common.Task) { thread_count = ols_config.thread_pool_count; enable_document_symbols = ols_config.enable_document_symbols; enable_hover = ols_config.enable_hover; + enable_format = ols_config.enable_format; config.enable_semantic_tokens = ols_config.enable_semantic_tokens; config.verbose = ols_config.verbose; @@ -525,6 +531,7 @@ request_initialize :: proc(task: ^common.Task) { }, documentSymbolProvider = enable_document_symbols, hoverProvider = enable_hover, + documentFormattingProvider = enable_format, }, }, id = id, @@ -688,6 +695,11 @@ request_signature_help :: proc(task: ^common.Task) { help: SignatureHelp; help, ok = get_signature_information(document, signature_params.position); + if !ok { + handle_error(.InternalError, id, writer); + return; + } + response := make_response_message( params = help, id = id, @@ -696,6 +708,47 @@ request_signature_help :: proc(task: ^common.Task) { send_response(response, writer); } +request_format_document :: proc(task: ^common.Task) { + + info := get_request_info(task); + + using info; + + defer document_release(document); + defer json.destroy_value(root); + defer free(info); + + params_object, ok := params.value.(json.Object); + + if !ok { + handle_error(.ParseError, id, writer); + return; + } + + format_params: DocumentFormattingParams; + + if unmarshal(params, format_params, context.temp_allocator) != .None { + handle_error(.ParseError, id, writer); + return; + } + + edit: [] TextEdit; + edit, ok = get_complete_format(document); + + if !ok { + handle_error(.InternalError, id, writer); + return; + } + + response := make_response_message( + params = edit, + id = id, + ); + + send_response(response, writer); + +} + notification_exit :: proc(task: ^common.Task) { info := get_request_info(task); using info; diff --git a/src/server/types.odin b/src/server/types.odin index a9d8983..9b8ecd3 100644 --- a/src/server/types.odin +++ b/src/server/types.odin @@ -24,6 +24,7 @@ ResponseParams :: union { [] DocumentSymbol, SemanticTokens, Hover, + [] TextEdit, }; ResponseMessage :: struct { @@ -87,6 +88,7 @@ ServerCapabilities :: struct { semanticTokensProvider: SemanticTokensOptions, documentSymbolProvider: bool, hoverProvider: bool, + documentFormattingProvider: bool, }; CompletionOptions :: struct { @@ -292,6 +294,7 @@ OlsConfig :: struct { enable_semantic_tokens: bool, enable_document_symbols: bool, enable_hover: bool, + enable_format: bool, verbose: bool, }; |