diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2021-05-22 22:45:32 +0200 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2021-05-22 22:45:32 +0200 |
| commit | 3c1a47890728bf0740c9b2d718b142a46fc061e3 (patch) | |
| tree | 7e17cfcbeae5891d5a6c5b46ea9edbc3225cf77b /src | |
| parent | d22445e3f9152d6ca43c10cc5ac5bfad50cb52ae (diff) | |
prepare to have global config aswell
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/config.odin | 6 | ||||
| -rw-r--r-- | src/server/format.odin | 2 | ||||
| -rw-r--r-- | src/server/requests.odin | 81 |
3 files changed, 46 insertions, 43 deletions
diff --git a/src/common/config.odin b/src/common/config.odin index 432794f..8bb7dc6 100644 --- a/src/common/config.odin +++ b/src/common/config.odin @@ -9,7 +9,11 @@ Config :: struct { running: bool, verbose: bool, debug_single_thread: bool, - enable_semantic_tokens: bool, //This will be removed when vscode client stops sending me semantic tokens after disabling it in requests initialize. + enable_format: bool, + enable_hover: bool, + enable_document_symbols: bool, + enable_semantic_tokens: bool, + thread_count: int, } config: Config;
\ No newline at end of file diff --git a/src/server/format.odin b/src/server/format.odin index d05ae19..b29669a 100644 --- a/src/server/format.odin +++ b/src/server/format.odin @@ -63,7 +63,7 @@ get_complete_format :: proc(document: ^Document) -> ([]TextEdit, bool) { }, end = { character = 1, - line = line, + line = line+1, }, }, }; diff --git a/src/server/requests.odin b/src/server/requests.odin index 26b26d4..f581f53 100644 --- a/src/server/requests.odin +++ b/src/server/requests.odin @@ -394,61 +394,60 @@ request_initialize :: proc (task: ^common.Task) { append(&config.workspace_folders, s); } - thread_count := 2; + read_ols_config :: proc(file: string, config: ^common.Config, uri: common.Uri) { + if data, ok := os.read_entire_file(file, context.temp_allocator); ok { - enable_document_symbols: bool; - enable_hover: bool; - enable_format: bool; + if value, err := json.parse(data = data, allocator = context.temp_allocator, parse_integers = true); err == .None { - if len(config.workspace_folders) > 0 { - - //right now just look at the first workspace - TODO(daniel, add multiple workspace support) - if uri, ok := common.parse_uri(config.workspace_folders[0].uri, context.temp_allocator); ok { - - ols_config_path := path.join(elems = {uri.path, "ols.json"}, allocator = context.temp_allocator); + ols_config: OlsConfig; - if data, ok := os.read_entire_file(ols_config_path, context.temp_allocator); ok { + if unmarshal(value, ols_config, context.temp_allocator) == .None { - if value, err := json.parse(data = data, allocator = context.temp_allocator, parse_integers = true); err == .None { + config.thread_count = ols_config.thread_pool_count; + config.enable_document_symbols = ols_config.enable_document_symbols; + config.enable_hover = ols_config.enable_hover; + config.enable_format = ols_config.enable_format; + config.enable_semantic_tokens = ols_config.enable_semantic_tokens; + config.verbose = ols_config.verbose; - ols_config: OlsConfig; + for p in ols_config.collections { - if unmarshal(value, ols_config, context.temp_allocator) == .None { + forward_path, _ := filepath.to_slash(p.path, context.temp_allocator); - 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; - - for p in ols_config.collections { - - forward_path, _ := filepath.to_slash(p.path, context.temp_allocator); - - if filepath.is_abs(p.path) { - config.collections[strings.clone(p.name)] = strings.clone(forward_path); - } else { - config.collections[strings.clone(p.name)] = path.join(elems = {uri.path, forward_path}, allocator = context.allocator); - } + if filepath.is_abs(p.path) { + config.collections[strings.clone(p.name)] = strings.clone(forward_path); + } else { + config.collections[strings.clone(p.name)] = path.join(elems = {uri.path, forward_path}, allocator = context.allocator); } + } - if ok := "" in config.collections; !ok { - config.collections[""] = uri.path; - } - } else { - log.errorf("Failed to unmarshal %v", ols_config_path); + if ok := "" in config.collections; !ok { + config.collections[""] = uri.path; } } else { - log.errorf("Failed to parse json %v", ols_config_path); + log.errorf("Failed to unmarshal %v", file); } } else { - log.errorf("Failed to read/find %v", ols_config_path); + log.errorf("Failed to parse json %v", file); } + } else { + log.errorf("Failed to read/find %v", file); + } + } + + //global config + + + //local specific + if len(config.workspace_folders) > 0 { + //right now just look at the first workspace - TODO(daniel, add multiple workspace support) + if uri, ok := common.parse_uri(config.workspace_folders[0].uri, context.temp_allocator); ok { + ols_config_path := path.join(elems = {uri.path, "ols.json"}, allocator = context.temp_allocator); + read_ols_config(ols_config_path, config, uri); } } - common.pool_init(&pool, thread_count); + common.pool_init(&pool, config.thread_count); common.pool_start(&pool); for format in initialize_params.capabilities.textDocument.hover.contentFormat { @@ -510,9 +509,9 @@ request_initialize :: proc (task: ^common.Task) { tokenModifiers = token_modifiers, }, }, - documentSymbolProvider = enable_document_symbols, - hoverProvider = enable_hover, - documentFormattingProvider = enable_format, + documentSymbolProvider = config.enable_document_symbols, + hoverProvider = config.enable_hover, + documentFormattingProvider = config.enable_format, }, }, id = id); |