Skip to content

Commit

Permalink
New config to only call check on saved package.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Gavin committed Apr 25, 2024
1 parent d0afaf1 commit 1f33639
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 52 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Options:

`enable_procedure_snippet`: Use snippets when completing procedures—adds parenthesis after the name. _(Enabled by default)_

`enable_checker_only_saved`: Turns on only calling the checker on the package being saved.

`odin_command`: Allows you to specify your Odin location, instead of just relying on the environment path.

`checker_args`: Pass custom arguments to `odin check`.
Expand Down
4 changes: 4 additions & 0 deletions misc/ols.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
}
},
"thread_pool_count": { "type": "integer" },
"enable_checker_only_saved": {
"type": "boolean",
"description": "Turns on only calling the checker on the package being saved"
},
"enable_semantic_tokens": {
"type": "boolean",
"description": "Turns on syntax highlighting."
Expand Down
59 changes: 30 additions & 29 deletions src/common/config.odin
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,36 @@ ConfigProfile :: struct {
}

Config :: struct {
workspace_folders: [dynamic]WorkspaceFolder,
completion_support_md: bool,
hover_support_md: bool,
signature_offset_support: bool,
collections: map[string]string,
running: bool,
verbose: bool,
enable_format: bool,
enable_hover: bool,
enable_document_symbols: bool,
enable_semantic_tokens: bool,
enable_inlay_hints: bool,
enable_procedure_context: bool,
enable_snippets: bool,
enable_references: bool,
enable_rename: bool,
enable_label_details: bool,
enable_std_references: bool,
enable_import_fixer: bool,
enable_fake_method: bool,
enable_procedure_snippet: bool,
disable_parser_errors: bool,
thread_count: int,
file_log: bool,
odin_command: string,
checker_args: string,
checker_targets: []string,
client_name: string,
profile: ConfigProfile,
workspace_folders: [dynamic]WorkspaceFolder,
completion_support_md: bool,
hover_support_md: bool,
signature_offset_support: bool,
collections: map[string]string,
running: bool,
verbose: bool,
enable_format: bool,
enable_hover: bool,
enable_document_symbols: bool,
enable_semantic_tokens: bool,
enable_inlay_hints: bool,
enable_procedure_context: bool,
enable_snippets: bool,
enable_references: bool,
enable_rename: bool,
enable_label_details: bool,
enable_std_references: bool,
enable_import_fixer: bool,
enable_fake_method: bool,
enable_procedure_snippet: bool,
enable_checker_only_saved: bool,
disable_parser_errors: bool,
thread_count: int,
file_log: bool,
odin_command: string,
checker_args: string,
checker_targets: []string,
client_name: string,
profile: ConfigProfile,
}

config: Config
9 changes: 7 additions & 2 deletions src/server/check.odin
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,18 @@ fallback_find_odin_directories :: proc(config: ^common.Config) -> []string {
return data[:]
}

check :: proc(paths: []string, writer: ^Writer, config: ^common.Config) {
check :: proc(paths: []string, uri: common.Uri, writer: ^Writer, config: ^common.Config) {
paths := paths

if len(paths) == 0 {
paths = fallback_find_odin_directories(config)
if config.enable_checker_only_saved {
paths = {path.dir(uri.path, context.temp_allocator)}
} else {
paths = fallback_find_odin_directories(config)
}
}


data := make([]byte, mem.Kilobyte * 200, context.temp_allocator)

buffer: []byte
Expand Down
7 changes: 6 additions & 1 deletion src/server/requests.odin
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ read_ols_initialize_options :: proc(
config.enable_procedure_snippet =
ols_config.enable_procedure_snippet.(bool) or_else config.enable_procedure_snippet

config.enable_checker_only_saved =
ols_config.enable_checker_only_saved.(bool) or_else config.enable_checker_only_saved


if ols_config.odin_command != "" {
config.odin_command = strings.clone(
ols_config.odin_command,
Expand Down Expand Up @@ -701,6 +705,7 @@ request_initialize :: proc(
config.enable_inlay_hints = false
config.enable_fake_method = false
config.enable_procedure_snippet = true
config.enable_checker_only_saved = false

read_ols_config :: proc(
file: string,
Expand Down Expand Up @@ -1258,7 +1263,7 @@ notification_did_save :: proc(
log.errorf("failed to collect symbols on save %v", ret)
}

check(config.profile.checker_path[:], writer, config)
check(config.profile.checker_path[:], corrected_uri, writer, config)

return .None
}
Expand Down
41 changes: 21 additions & 20 deletions src/server/types.odin
Original file line number Diff line number Diff line change
Expand Up @@ -336,26 +336,27 @@ TextDocumentSyncOptions :: struct {
}

OlsConfig :: struct {
collections: [dynamic]OlsConfigCollection,
thread_pool_count: Maybe(int),
enable_semantic_tokens: Maybe(bool),
enable_document_symbols: Maybe(bool),
enable_format: Maybe(bool),
enable_hover: Maybe(bool),
enable_procedure_context: Maybe(bool),
enable_snippets: Maybe(bool),
enable_inlay_hints: Maybe(bool),
enable_references: Maybe(bool),
enable_fake_methods: Maybe(bool),
enable_procedure_snippet: Maybe(bool),
disable_parser_errors: Maybe(bool),
verbose: Maybe(bool),
file_log: Maybe(bool),
odin_command: string,
checker_args: string,
checker_targets: []string,
profiles: [dynamic]common.ConfigProfile,
profile: string,
collections: [dynamic]OlsConfigCollection,
thread_pool_count: Maybe(int),
enable_semantic_tokens: Maybe(bool),
enable_document_symbols: Maybe(bool),
enable_format: Maybe(bool),
enable_hover: Maybe(bool),
enable_procedure_context: Maybe(bool),
enable_snippets: Maybe(bool),
enable_inlay_hints: Maybe(bool),
enable_references: Maybe(bool),
enable_fake_methods: Maybe(bool),
enable_procedure_snippet: Maybe(bool),
enable_checker_only_saved: Maybe(bool),
disable_parser_errors: Maybe(bool),
verbose: Maybe(bool),
file_log: Maybe(bool),
odin_command: string,
checker_args: string,
checker_targets: []string,
profiles: [dynamic]common.ConfigProfile,
profile: string,
}

OlsConfigCollection :: struct {
Expand Down

0 comments on commit 1f33639

Please sign in to comment.