Skip to content

Commit 31cda7e

Browse files
committed
Add new config for "enable_procedure_snippet"
1 parent 6bcf5f9 commit 31cda7e

File tree

5 files changed

+54
-28
lines changed

5 files changed

+54
-28
lines changed

src/common/config.odin

+2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ Config :: struct {
2121
enable_std_references: bool,
2222
enable_import_fixer: bool,
2323
enable_fake_method: bool,
24+
enable_procedure_snippet: bool,
2425
disable_parser_errors: bool,
2526
thread_count: int,
2627
file_log: bool,
2728
odin_command: string,
2829
checker_args: string,
30+
checker_targets: []string,
2931
client_name: string,
3032
}
3133

src/server/check.odin

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package server
22

3+
import "core:encoding/json"
34
import "core:fmt"
5+
import "core:intrinsics"
46
import "core:log"
57
import "core:mem"
68
import "core:os"
7-
import "core:strings"
8-
import "core:slice"
9-
import "core:strconv"
10-
import "core:encoding/json"
9+
import "core:path/filepath"
1110
import path "core:path/slashpath"
1211
import "core:runtime"
13-
import "core:thread"
12+
import "core:slice"
13+
import "core:strconv"
14+
import "core:strings"
1415
import "core:sync"
15-
import "core:path/filepath"
16-
import "core:intrinsics"
1716
import "core:text/scanner"
17+
import "core:thread"
1818

1919
import "shared:common"
2020

@@ -46,16 +46,16 @@ check :: proc(uri: common.Uri, writer: ^Writer, config: ^common.Config) {
4646
}
4747

4848
if code, ok, buffer = common.run_executable(
49-
fmt.tprintf(
50-
"%v check %s %s -no-entry-point %s %s",
51-
command,
52-
path.dir(uri.path, context.temp_allocator),
53-
strings.to_string(collection_builder),
54-
config.checker_args,
55-
ODIN_OS == .Linux || ODIN_OS == .Darwin ? "2>&1" : "",
56-
),
57-
&data,
58-
); !ok {
49+
fmt.tprintf(
50+
"%v check %s %s -no-entry-point %s %s",
51+
command,
52+
path.dir(uri.path, context.temp_allocator),
53+
strings.to_string(collection_builder),
54+
config.checker_args,
55+
ODIN_OS == .Linux || ODIN_OS == .Darwin ? "2>&1" : "",
56+
),
57+
&data,
58+
); !ok {
5959
log.errorf(
6060
"Odin check failed with code %v for file %v",
6161
code,
@@ -195,10 +195,10 @@ check :: proc(uri: common.Uri, writer: ^Writer, config: ^common.Config) {
195195

196196
append(
197197
&errors[error.uri],
198-
Diagnostic{
198+
Diagnostic {
199199
code = "checker",
200200
severity = .Error,
201-
range = {
201+
range = {
202202
start = {character = error.column, line = error.line - 1},
203203
end = {character = 0, line = error.line},
204204
},

src/server/completion.odin

+6-2
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,9 @@ get_selector_completion :: proc(
613613
documentation = symbol.doc,
614614
}
615615

616-
if symbol.type == .Function && common.config.enable_snippets {
616+
if symbol.type == .Function &&
617+
common.config.enable_snippets &&
618+
common.config.enable_procedure_snippet {
617619
item.insertText = fmt.tprintf("%v($0)", item.label)
618620
item.insertTextFormat = .Snippet
619621
item.command = Command {
@@ -1376,7 +1378,9 @@ get_identifier_completion :: proc(
13761378

13771379
item.kind = symbol_type_to_completion_kind(result.type)
13781380

1379-
if result.type == .Function && common.config.enable_snippets {
1381+
if result.type == .Function &&
1382+
common.config.enable_snippets &&
1383+
common.config.enable_procedure_snippet {
13801384
item.insertText = fmt.tprintf("%v($0)", item.label)
13811385
item.insertTextFormat = .Snippet
13821386
item.deprecated = .Deprecated in result.flags

src/server/requests.odin

+25-7
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ read_ols_initialize_options :: proc(
426426
config.enable_rename =
427427
ols_config.enable_references.(bool) or_else config.enable_rename
428428

429+
config.enable_procedure_snippet =
430+
ols_config.enable_procedure_snippet.(bool) or_else config.enable_procedure_snippet
431+
429432
if ols_config.odin_command != "" {
430433
config.odin_command = strings.clone(
431434
ols_config.odin_command,
@@ -440,6 +443,20 @@ read_ols_initialize_options :: proc(
440443
)
441444
}
442445

446+
config.checker_targets = slice.clone(
447+
ols_config.checker_targets,
448+
context.allocator,
449+
)
450+
451+
found_target := false
452+
453+
for target in config.checker_targets {
454+
if ODIN_OS in os_enum_to_string {
455+
found_target = true
456+
}
457+
}
458+
459+
443460
config.enable_inlay_hints =
444461
ols_config.enable_inlay_hints.(bool) or_else config.enable_inlay_hints
445462
config.enable_fake_method =
@@ -582,6 +599,7 @@ request_initialize :: proc(
582599
config.checker_args = ""
583600
config.enable_inlay_hints = false
584601
config.enable_fake_method = false
602+
config.enable_procedure_snippet = true
585603

586604
read_ols_config :: proc(
587605
file: string,
@@ -684,9 +702,9 @@ request_initialize :: proc(
684702
}
685703

686704
response := make_response_message(
687-
params = ResponseInitializeParams{
688-
capabilities = ServerCapabilities{
689-
textDocumentSync = TextDocumentSyncOptions{
705+
params = ResponseInitializeParams {
706+
capabilities = ServerCapabilities {
707+
textDocumentSync = TextDocumentSyncOptions {
690708
openClose = true,
691709
change = 2,
692710
save = {includeText = true},
@@ -695,19 +713,19 @@ request_initialize :: proc(
695713
workspaceSymbolProvider = true,
696714
referencesProvider = config.enable_references,
697715
definitionProvider = true,
698-
completionProvider = CompletionOptions{
716+
completionProvider = CompletionOptions {
699717
resolveProvider = false,
700718
triggerCharacters = completionTriggerCharacters,
701719
completionItem = {labelDetailsSupport = true},
702720
},
703-
signatureHelpProvider = SignatureHelpOptions{
721+
signatureHelpProvider = SignatureHelpOptions {
704722
triggerCharacters = signatureTriggerCharacters,
705723
retriggerCharacters = signatureRetriggerCharacters,
706724
},
707-
semanticTokensProvider = SemanticTokensOptions{
725+
semanticTokensProvider = SemanticTokensOptions {
708726
range = config.enable_semantic_tokens,
709727
full = config.enable_semantic_tokens,
710-
legend = SemanticTokensLegend{
728+
legend = SemanticTokensLegend {
711729
tokenTypes = token_types,
712730
tokenModifiers = token_modifiers,
713731
},

src/server/types.odin

+2
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,13 @@ OlsConfig :: struct {
347347
enable_inlay_hints: Maybe(bool),
348348
enable_references: Maybe(bool),
349349
enable_fake_methods: Maybe(bool),
350+
enable_procedure_snippet: Maybe(bool),
350351
disable_parser_errors: Maybe(bool),
351352
verbose: Maybe(bool),
352353
file_log: Maybe(bool),
353354
odin_command: string,
354355
checker_args: string,
356+
checker_targets: []string,
355357
}
356358

357359
OlsConfigCollection :: struct {

0 commit comments

Comments
 (0)