aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin/builtin.odin8
-rw-r--r--misc/ols.schema.json10
-rw-r--r--src/common/config.odin62
-rw-r--r--src/odin/printer/document.odin2
-rw-r--r--src/odin/printer/visit.odin57
-rw-r--r--src/server/inlay_hints.odin108
-rw-r--r--src/server/requests.odin12
-rw-r--r--src/server/types.odin44
8 files changed, 224 insertions, 79 deletions
diff --git a/builtin/builtin.odin b/builtin/builtin.odin
index e6a634c..b4a3e38 100644
--- a/builtin/builtin.odin
+++ b/builtin/builtin.odin
@@ -34,6 +34,14 @@ conj :: proc(value: Complex_Or_Quaternion) -> Complex_Or_Quaternion ---
@builtin unreachable :: proc() -> ! ---
+@(private="file") _raw_data_slice :: proc(value: []$E) -> [^]E ---
+@(private="file") _raw_data_dynamic :: proc(value: [dynamic]$E) -> [^]E ---
+@(private="file") _raw_data_array :: proc(value: ^[$N]$E) -> [^]E ---
+@(private="file") _raw_data_simd :: proc(value: ^#simd[$N]$E) -> [^]E ---
+@(private="file") _raw_data_string :: proc(value: string) -> [^]byte ---
+// raw_data is a built-in procedure which returns the underlying data of a built-in data type as a Multi-Pointer.
+@builtin raw_data :: proc{_raw_data_slice, _raw_data_dynamic, _raw_data_array, _raw_data_simd, _raw_data_string}
+
/*
This is interally from the compiler
*/
diff --git a/misc/ols.schema.json b/misc/ols.schema.json
index 04b1006..f46a24e 100644
--- a/misc/ols.schema.json
+++ b/misc/ols.schema.json
@@ -43,6 +43,16 @@
"type": "boolean",
"description": "Turn on inlay hints for editors that support it."
},
+ "enable_inlay_hints_params": {
+ "type": "boolean",
+ "description": "Turn on inlay hints for (non-default) parameters.",
+ "default": true
+ },
+ "enable_inlay_hints_default_params": {
+ "type": "boolean",
+ "description": "Turn on inlay hints for default parameters.",
+ "default": true
+ },
"enable_procedure_snippet": {
"type": "boolean",
"description": "Use snippets when completing procedures—adds parenthesis after the name.",
diff --git a/src/common/config.odin b/src/common/config.odin
index 6ca8bc9..27bc1ac 100644
--- a/src/common/config.odin
+++ b/src/common/config.odin
@@ -7,36 +7,38 @@ 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,
- 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,
+ 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_inlay_hints_params: bool,
+ enable_inlay_hints_default_params: 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
diff --git a/src/odin/printer/document.odin b/src/odin/printer/document.odin
index 2719585..57c3e4f 100644
--- a/src/odin/printer/document.odin
+++ b/src/odin/printer/document.odin
@@ -1,5 +1,6 @@
package odin_printer
+import "core:fmt"
import "core:strings"
Document :: union {
@@ -597,6 +598,7 @@ format :: proc(
strings.write_string(builder, v.value)
consumed += len(v.value)
} else if data.mode == .Fill && v.newline {
+ flush_line_suffix(builder, &suffix_builder)
format_newline(
data.indentation,
data.alignment,
diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin
index 9407ec8..c408147 100644
--- a/src/odin/printer/visit.odin
+++ b/src/odin/printer/visit.odin
@@ -2658,12 +2658,30 @@ visit_proc_type :: proc(
document = cons(document, text("("))
}
+ contain_comments := contains_comments_in_range(
+ p,
+ proc_type.pos,
+ proc_type.end,
+ )
+
+ options: List_Options
+
+ if contain_comments {
+ options |= {.Enforce_Newline}
+ }
+
document = cons(
document,
nest(
cons(
len(proc_type.params.list) > 0 ? break_with("") : empty(),
- visit_signature_list(p, proc_type.params, true, false),
+ visit_signature_list(
+ p,
+ proc_type.params,
+ true,
+ false,
+ options,
+ ),
),
),
)
@@ -2725,6 +2743,10 @@ visit_proc_type :: proc(
document = cons_with_nopl(document, text("!"))
}
+ if contain_comments {
+ return enforce_break(document)
+ }
+
return document
}
@@ -2854,25 +2876,48 @@ visit_signature_list :: proc(
list: ^ast.Field_List,
contains_body: bool,
remove_blank: bool,
+ options := List_Options{},
) -> ^Document {
document := empty()
for field, i in list.list {
+ p.source_position = field.pos
+
document = cons(
document,
visit_signature_field(p, field, remove_blank),
)
if i != len(list.list) - 1 {
- document = cons(document, text(","), break_with_space())
+ if .Enforce_Newline in options {
+ document = cons(document, text(","))
+ } else {
+ document = cons(document, text(","), break_with_space())
+ }
} else {
- document =
- len(list.list) > 1 || contains_body \
- ? cons(document, if_break(",")) \
- : document
+ if .Enforce_Newline not_in options {
+ document =
+ len(list.list) > 1 || contains_body \
+ ? cons(document, if_break(",")) \
+ : document
+ } else {
+ document = cons(document, text(","))
+ }
+
+ }
+
+ if (i != len(list.list) - 1 && .Enforce_Newline in options) {
+ comment, _ := visit_comments(p, list.list[i + 1].pos)
+ document = cons(document, comment, newline(1))
+ } else if .Enforce_Newline in options {
+ comment, _ := visit_comments(p, list.list[i].end)
+ document = cons(document, comment)
}
}
+ comment, _ := visit_comments(p, list.end)
+ document = cons(document, comment)
+
return document
}
diff --git a/src/server/inlay_hints.odin b/src/server/inlay_hints.odin
index 8085baa..86d1bf5 100644
--- a/src/server/inlay_hints.odin
+++ b/src/server/inlay_hints.odin
@@ -9,6 +9,7 @@ import "src:common"
get_inlay_hints :: proc(
document: ^Document,
symbols: map[uintptr]SymbolAndNode,
+ config: ^common.Config,
) -> (
[]InlayHint,
bool,
@@ -58,9 +59,12 @@ get_inlay_hints :: proc(
loop: for node_call in &data.calls {
symbol_arg_count := 0
is_selector_call := false
+ is_ellipsis := false
+ has_added_default := false
call := node_call.derived.(^ast.Call_Expr)
+ // TODO: support this (inlay hints in calls that use named args, e.g. `foobar(foo=bar)`
for arg in call.args {
if _, ok := arg.derived.(^ast.Field_Value); ok {
continue loop
@@ -81,17 +85,13 @@ get_inlay_hints :: proc(
}
for name in arg.names {
- if symbol_arg_count >= len(call.args) {
- continue loop
- }
-
label := ""
- is_ellipsis := false
+ is_current_ellipsis := false
if arg.type != nil {
if ellipsis, ok := arg.type.derived.(^ast.Ellipsis);
ok {
- is_ellipsis = true
+ is_current_ellipsis = true
}
}
@@ -108,24 +108,92 @@ get_inlay_hints :: proc(
continue loop
}
- range := common.get_token_range(
- call.args[symbol_arg_count],
- string(document.text),
- )
- hint := InlayHint {
- kind = .Parameter,
- label = fmt.tprintf("%v = ", label),
- position = range.start,
- }
- append(&hints, hint)
+ if is_ellipsis || symbol_arg_count >= len(call.args) {
+ if arg.default_value == nil {
+ continue loop
+ }
- symbol_arg_count += 1
+ if !config.enable_inlay_hints_default_params {
+ continue loop
+ }
- if is_ellipsis {
- continue loop
+ value := common.node_to_string(arg.default_value)
+
+ call_range := common.get_token_range(
+ call,
+ string(document.text),
+ )
+
+ position: common.Position
+ position = call_range.end
+ position.character -= 1
+
+ has_trailing_comma: bool;{
+ if !has_added_default {
+ till_end := string(
+ document.text[:call.close.offset],
+ )
+ trailing_loop: #reverse for ch in till_end {
+ switch ch {
+ case ' ', '\t', '\n':
+ case ',':
+ has_trailing_comma = true
+ break trailing_loop
+ case:
+ break trailing_loop
+ }
+ }
+ }
+ }
+
+ hint := InlayHint {
+ kind = .Parameter,
+ label = fmt.tprintf(
+ "%s %v := %v",
+ has_trailing_comma ? "" : ",",
+ label,
+ value,
+ ),
+ position = position,
+ }
+ append(&hints, hint)
+
+ has_added_default = true
+ } else if config.enable_inlay_hints_params {
+
+ // if the arg name and param name are the same, don't add it.
+ same_name: bool
+ #partial switch v in
+ call.args[symbol_arg_count].derived_expr {
+ case ^ast.Ident:
+ same_name = label == v.name
+ case ^ast.Poly_Type:
+ if ident, ok := v.type.derived.(^ast.Ident);
+ ok {
+ same_name = label == ident.name
+ }
+ }
+
+ if !same_name {
+ range := common.get_token_range(
+ call.args[symbol_arg_count],
+ string(document.text),
+ )
+ hint := InlayHint {
+ kind = .Parameter,
+ label = fmt.tprintf("%v = ", label),
+ position = range.start,
+ }
+ append(&hints, hint)
+ }
+ }
+
+ if is_current_ellipsis {
+ is_ellipsis = true
}
- }
+ symbol_arg_count += 1
+ }
}
}
}
diff --git a/src/server/requests.odin b/src/server/requests.odin
index b47c4a0..dfab097 100644
--- a/src/server/requests.odin
+++ b/src/server/requests.odin
@@ -496,6 +496,11 @@ read_ols_initialize_options :: proc(
config.enable_inlay_hints =
ols_config.enable_inlay_hints.(bool) or_else config.enable_inlay_hints
+ config.enable_inlay_hints_params =
+ ols_config.enable_inlay_hints_params.(bool) or_else config.enable_inlay_hints_params
+ config.enable_inlay_hints_default_params =
+ ols_config.enable_inlay_hints_default_params.(bool) or_else config.enable_inlay_hints_default_params
+
config.enable_fake_method =
ols_config.enable_fake_methods.(bool) or_else config.enable_fake_method
@@ -689,6 +694,10 @@ request_initialize :: proc(
config.enable_hover = true
config.enable_format = true
+ config.enable_inlay_hints = false
+ config.enable_inlay_hints_params = true
+ config.enable_inlay_hints_default_params = true
+
config.disable_parser_errors = false
config.thread_count = 2
config.enable_document_symbols = true
@@ -703,7 +712,6 @@ request_initialize :: proc(
config.enable_rename = true
config.odin_command = ""
config.checker_args = ""
- config.enable_inlay_hints = false
config.enable_fake_method = false
config.enable_procedure_snippet = true
config.enable_checker_only_saved = false
@@ -1441,7 +1449,7 @@ request_inlay_hint :: proc(
resolve_entire_file_cached(document)
if file, ok := file_resolve_cache.files[document.uri.uri]; ok {
- hints, ok = get_inlay_hints(document, file.symbols)
+ hints, ok = get_inlay_hints(document, file.symbols, config)
}
if !ok {
diff --git a/src/server/types.odin b/src/server/types.odin
index 5079bf6..7eb3a10 100644
--- a/src/server/types.odin
+++ b/src/server/types.odin
@@ -342,27 +342,29 @@ 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),
- 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,
+ 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_inlay_hints_params: Maybe(bool),
+ enable_inlay_hints_default_params: 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 {