From 3b8ea5cda886447cc1c37b0d7f272b2194ccb332 Mon Sep 17 00:00:00 2001 From: Damian Tarnawski Date: Fri, 14 Jun 2024 22:57:03 +0200 Subject: Minor fixes to tm grammars - add `\` to punctuation - change scope for `context` to a `keyword.context.odin` - fix edge case with `case` being matched in struct declarations --- editors/vscode/syntaxes/odin.tmLanguage.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/editors/vscode/syntaxes/odin.tmLanguage.json b/editors/vscode/syntaxes/odin.tmLanguage.json index d9349b9..3050aaf 100644 --- a/editors/vscode/syntaxes/odin.tmLanguage.json +++ b/editors/vscode/syntaxes/odin.tmLanguage.json @@ -284,8 +284,8 @@ }, "case-clause": { "name": "meta.case-clause.expr.odin", - "begin": "case", - "beginCaptures": { "0": { "name": "keyword.control.case.odin" } }, + "begin": "\\b(case)\\b", + "beginCaptures": { "1": { "name": "keyword.control.case.odin" } }, "end": ":", "endCaptures": { "0": { "name": "punctuation.definition.section.case-statement.odin" } }, "patterns": [ { "include": "#expressions" } ] @@ -435,7 +435,7 @@ "match": "\\b(auto_cast|distinct|using)\\b" }, { - "name": "variable.other.object.odin", + "name": "keyword.context.odin", "match": "\\b(context)\\b" }, { @@ -618,7 +618,7 @@ "patterns": [ { "name": "punctuation.odin", - "match": "\\(|\\)|\\{|\\}|;|\\[|\\]|\\.|," + "match": "\\(|\\)|\\{|\\}|;|\\[|\\]|\\.|,|\\\\" } ] } -- cgit v1.2.3 From 36e6b82ec59af21148cea5e05fbbee4299f2987c Mon Sep 17 00:00:00 2001 From: Damian Tarnawski Date: Fri, 14 Jun 2024 23:12:51 +0200 Subject: Change scope for tags to `entity.name.tag.odin` --- editors/vscode/syntaxes/odin.tmLanguage.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editors/vscode/syntaxes/odin.tmLanguage.json b/editors/vscode/syntaxes/odin.tmLanguage.json index 3050aaf..8417504 100644 --- a/editors/vscode/syntaxes/odin.tmLanguage.json +++ b/editors/vscode/syntaxes/odin.tmLanguage.json @@ -503,7 +503,7 @@ "match": "@|(\\||\\!|:|\\+|-|\\*|/|%|\\<\\\\>?|\\~)=?|=|: : ?|\\.\\.|\\$" }, { - "name": "keyword.other.odin", + "name": "entity.name.tag.odin", "match": "#[A-Za-z_]\\w*" } ] -- cgit v1.2.3 From 6e6528da0b817366393f534cda4a59a19afb076b Mon Sep 17 00:00:00 2001 From: Hamza Ali Date: Tue, 18 Jun 2024 13:52:29 +0500 Subject: add additional completion snippets for dynamic arrays --- src/server/completion.odin | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/server/completion.odin b/src/server/completion.odin index e404b78..91cc790 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -1947,6 +1947,56 @@ append_magic_dynamic_array_completion :: proc( append(items, item) } + // This proc is shared between slices and dynamic arrays. + if _, ok := symbol.value.(SymbolDynamicArrayValue); !ok { + return + } + + //pop + { + text := fmt.tprintf("pop(&%v)", symbol_str) + + item := CompletionItem { + label = "pop", + kind = .Function, + detail = "pop", + textEdit = TextEdit { + newText = text, + range = {start = range.end, end = range.end}, + }, + additionalTextEdits = additionalTextEdits, + } + + append(items, item) + } + + dynamic_array_builtins := []string { + "append", + "unordered_remove", + "ordered_remove", + "resize", + "reserve", + "shrink", + "inject_at", + "assign_at", + } + + for name in dynamic_array_builtins { + item := CompletionItem { + label = name, + kind = .Snippet, + detail = name, + additionalTextEdits = additionalTextEdits, + textEdit = TextEdit { + newText = fmt.tprintf("%s(&%v, $0)", name, symbol_str), + range = {start = range.end, end = range.end}, + }, + insertTextFormat = .Snippet, + InsertTextMode = .adjustIndentation, + } + + append(items, item) + } } append_magic_union_completion :: proc( -- cgit v1.2.3 From 461d80b90753debf1987234733bd943023bd565a Mon Sep 17 00:00:00 2001 From: Hamza Ali Date: Tue, 18 Jun 2024 21:10:39 +0500 Subject: snippet completion: handle dynamic arrays with any level of pointers --- src/server/completion.odin | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/server/completion.odin b/src/server/completion.odin index 91cc790..d3dfa08 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -1952,16 +1952,26 @@ append_magic_dynamic_array_completion :: proc( return } + prefix := "&" + suffix := "" + if symbol.pointers > 0 { + prefix = "" + suffix = common.repeat( + "^", + symbol.pointers - 1, + context.temp_allocator, + ) + } + ptr_symbol_str := fmt.tprint(prefix, symbol_str, suffix, sep = "") + //pop { - text := fmt.tprintf("pop(&%v)", symbol_str) - item := CompletionItem { label = "pop", kind = .Function, detail = "pop", textEdit = TextEdit { - newText = text, + newText = fmt.tprintf("pop(%v)", ptr_symbol_str), range = {start = range.end, end = range.end}, }, additionalTextEdits = additionalTextEdits, @@ -1988,7 +1998,7 @@ append_magic_dynamic_array_completion :: proc( detail = name, additionalTextEdits = additionalTextEdits, textEdit = TextEdit { - newText = fmt.tprintf("%s(&%v, $0)", name, symbol_str), + newText = fmt.tprintf("%s(%v, $0)", name, ptr_symbol_str), range = {start = range.end, end = range.end}, }, insertTextFormat = .Snippet, -- cgit v1.2.3 From 6ca719d281e5c77ee95b50c561c103b15ad31b8f Mon Sep 17 00:00:00 2001 From: Damian Tarnawski Date: Mon, 24 Jun 2024 20:31:25 +0200 Subject: Add punctuation tokens to comments and inline some rules --- editors/vscode/syntaxes/odin.tmLanguage.json | 88 ++++++++++++---------------- 1 file changed, 36 insertions(+), 52 deletions(-) diff --git a/editors/vscode/syntaxes/odin.tmLanguage.json b/editors/vscode/syntaxes/odin.tmLanguage.json index 8417504..05f50bf 100644 --- a/editors/vscode/syntaxes/odin.tmLanguage.json +++ b/editors/vscode/syntaxes/odin.tmLanguage.json @@ -359,27 +359,22 @@ { "name": "comment.line.double-slash.odin", "begin": "//", + "beginCaptures": {"0": {"name": "punctuation.definition.comment.odin"}}, "end": "\n" } ] }, "block-comment": { - "patterns": [ - { - "name": "comment.block.odin", - "begin": "/\\*", - "end": "\\*/", - "patterns": [ { "include": "#block-comment" } ] - } - ] + "name": "comment.block.odin", + "begin": "/\\*", + "beginCaptures": {"0": {"name": "punctuation.definition.comment.begin.odin"}}, + "end": "\\*/", + "endCaptures": {"0": {"name": "punctuation.definition.comment.end.odin"}}, + "patterns": [ { "include": "#block-comment" } ] }, "type-name": { - "patterns": [ - { - "name": "entity.name.type.odin", - "match": "\\b[A-Za-z_]\\w*\\b" - } - ] + "name": "entity.name.type.odin", + "match": "\\b[A-Za-z_]\\w*\\b" }, "type-parameter": { "captures": { @@ -389,12 +384,8 @@ "match": "(\\$)\\s*(\\b[A-Za-z_]\\w*\\b)" }, "variable-name": { - "patterns": [ - { - "name": "variable.name.odin", - "match": "\\b[A-Za-z_]\\w*\\b" - } - ] + "name": "variable.name.odin", + "match": "\\b[A-Za-z_]\\w*\\b" }, "keywords": { "patterns": [ @@ -570,34 +561,31 @@ }, "strings": { "patterns": [ - { "include": "#strings-quoted-double" }, - { "include": "#strings-quoted-single" }, - { "include": "#strings-quoted-raw" } + { + "name": "string.quoted.double.odin", + "begin": "\"", + "beginCaptures": { "0": { "name": "punctuation.definition.string.begin.odin" } }, + "end": "\"", + "endCaptures": { "0": { "name": "punctuation.definition.string.end.odin" } }, + "patterns": [ { "include": "#string-escaped-char" } ] + }, + { + "name": "string.quoted.single.odin", + "begin": "'", + "beginCaptures": { "0": { "name": "punctuation.definition.string.begin.odin" } }, + "end": "'", + "endCaptures": { "0": { "name": "punctuation.definition.string.end.odin" } }, + "patterns": [ { "include": "#string-escaped-char" } ] + }, + { + "name": "string.quoted.raw.odin", + "begin": "`", + "beginCaptures": { "0": { "name": "punctuation.definition.string.begin.odin" } }, + "end": "`", + "endCaptures": { "0": { "name": "punctuation.definition.string.end.odin" } } + } ] }, - "strings-quoted-double": { - "name": "string.quoted.double.odin", - "begin": "\"", - "beginCaptures": { "0": { "name": "punctuation.definition.string.begin.odin" } }, - "end": "\"", - "endCaptures": { "0": { "name": "punctuation.definition.string.end.odin" } }, - "patterns": [ { "include": "#string-escaped-char" } ] - }, - "strings-quoted-single": { - "name": "string.quoted.single.odin", - "begin": "'", - "beginCaptures": { "0": { "name": "punctuation.definition.string.begin.odin" } }, - "end": "'", - "endCaptures": { "0": { "name": "punctuation.definition.string.end.odin" } }, - "patterns": [ { "include": "#string-escaped-char" } ] - }, - "strings-quoted-raw": { - "name": "string.quoted.raw.odin", - "begin": "`", - "beginCaptures": { "0": { "name": "punctuation.definition.string.begin.odin" } }, - "end": "`", - "endCaptures": { "0": { "name": "punctuation.definition.string.end.odin" } } - }, "string-escaped-char": { "patterns": [ { @@ -615,12 +603,8 @@ ] }, "punctuation": { - "patterns": [ - { - "name": "punctuation.odin", - "match": "\\(|\\)|\\{|\\}|;|\\[|\\]|\\.|,|\\\\" - } - ] + "name": "punctuation.odin", + "match": "\\(|\\)|\\{|\\}|;|\\[|\\]|\\.|,|\\\\" } }, "scopeName": "source.odin" -- cgit v1.2.3 From 3870fa27c603e66dc24c33bd3693fb8b30b19f01 Mon Sep 17 00:00:00 2001 From: Damian Tarnawski Date: Tue, 25 Jun 2024 15:44:23 +0200 Subject: Add spread and range operators to the syntax highlighting --- editors/vscode/syntaxes/odin.tmLanguage.json | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/editors/vscode/syntaxes/odin.tmLanguage.json b/editors/vscode/syntaxes/odin.tmLanguage.json index 05f50bf..6f44764 100644 --- a/editors/vscode/syntaxes/odin.tmLanguage.json +++ b/editors/vscode/syntaxes/odin.tmLanguage.json @@ -389,11 +389,6 @@ }, "keywords": { "patterns": [ - { - "name": "keyword.tag.odin", - "comment": "Use #name to use a pattern", - "match": "\\b([#@]\\s*[A-Za-z_]\\w*)\\b" - }, { "name": "keyword.control.odin", "match": "\\b(import|foreign|package)\\b" @@ -454,28 +449,36 @@ "match": "\\b(struct|enum|union|map|bit_set|bit_field|matrix)\\b" }, { - "name": "keyword.operator.assignment.compound", + "name": "keyword.operator.assignment.compound.odin", "match": "[+\\-*/%]=|%%=" }, { - "name": "keyword.operator.assignment.compound.bitwise", + "name": "keyword.operator.assignment.compound.bitwise.odin", "match": "\\|=|~=|&~?=|<<=|>>=" }, { - "name": "keyword.operator.comparison", + "name": "keyword.operator.comparison.odin", "match": "==|!=" }, { - "name": "keyword.operator.relational", + "name": "keyword.operator.relational.odin", "match": "[<>]=?" }, + { + "name": "keyword.operator.range.odin", + "match": "\\.\\.[<=]" + }, + { + "name": "keyword.operator.spread.odin", + "match": "\\.\\." + }, { "name": "keyword.operator.assignment.odin", "match": ":[:=]|=" }, { "name": "keyword.operator.address.odin", - "match": "\\&" + "match": "&" }, { "name": "keyword.operator.address.odin", @@ -491,7 +494,7 @@ }, { "name": "keyword.operator.odin", - "match": "@|(\\||\\!|:|\\+|-|\\*|/|%|\\<\\\\>?|\\~)=?|=|: : ?|\\.\\.|\\$" + "match": "@|(\\||\\!|:|\\+|-|\\*|/|%|\\<\\\\>?|\\~)=?|=|: : ?|\\$" }, { "name": "entity.name.tag.odin", -- cgit v1.2.3 From 10d9ea3836546d30c15d8ee9d842ee432e58fbab Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Thu, 27 Jun 2024 16:34:15 +0200 Subject: Fix @(require) import "core:fmt" This previously showed a syntax error and that was fixed upstream in `core:odin` in aa27cd4b. Make this work in the OLS formatter as well. --- src/odin/printer/visit.odin | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index cbf63ed..9407ec8 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -327,6 +327,13 @@ visit_decl :: proc( case ^Import_Decl: document := move_line(p, decl.pos) + if len(v.attributes) > 0 { + document = cons( + document, + visit_attributes(p, &v.attributes, v.pos), + ) + } + if v.name.text != "" { document = cons( document, -- cgit v1.2.3 From 5516a7b1f029f1dde5ba2f7a73db57eb9cd92745 Mon Sep 17 00:00:00 2001 From: blob1807 <12388588+blob1807@users.noreply.github.com> Date: Fri, 28 Jun 2024 13:23:55 +1000 Subject: Add support for syntax highlighting in md Add support for syntax highlighting with in mark down fenced code block. --- editors/vscode/package.json | 10 ++++++++ editors/vscode/syntaxes/codeblock.json | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 editors/vscode/syntaxes/codeblock.json diff --git a/editors/vscode/package.json b/editors/vscode/package.json index abbd4d7..66e9bc4 100644 --- a/editors/vscode/package.json +++ b/editors/vscode/package.json @@ -114,6 +114,16 @@ "language": "odin", "scopeName": "source.odin", "path": "./syntaxes/odin.tmLanguage.json" + }, + { + "scopeName": "markdown.odin.codeblock", + "path": "./syntaxes/codeblock.json", + "injectTo": [ + "text.html.markdown" + ], + "embeddedLanguages": { + "meta.embedded.block.odin": "odin" + } } ], "breakpoints": [ diff --git a/editors/vscode/syntaxes/codeblock.json b/editors/vscode/syntaxes/codeblock.json new file mode 100644 index 0000000..0f3ee2e --- /dev/null +++ b/editors/vscode/syntaxes/codeblock.json @@ -0,0 +1,45 @@ +{ + "comment": "Taken from https://github.com/microsoft/vscode/blob/main/extensions/markdown-basics/syntaxes/markdown.tmLanguage.json", + "injectionSelector": "L:text.html.markdown", + "patterns": [ + { + "include": "#fenced_code_block_odin" + } + ], + "repository": { + "fenced_code_block_odin": { + "begin": "(^|\\G)(\\s*)(`{3,}|~{3,})\\s*(?i:(odin)((\\s+|:|,|\\{|\\?)[^`]*)?$)", + "name": "markup.fenced_code.block.markdown", + "end": "(^|\\G)(\\2|\\s{0,3})(\\3)\\s*$", + "beginCaptures": { + "3": { + "name": "punctuation.definition.markdown" + }, + "4": { + "name": "fenced_code.block.language.markdown" + }, + "5": { + "name": "fenced_code.block.language.attributes.markdown" + } + }, + "endCaptures": { + "3": { + "name": "punctuation.definition.markdown" + } + }, + "patterns": [ + { + "begin": "(^|\\G)(\\s*)(.*)", + "while": "(^|\\G)(?!\\s*([`~]{3,})\\s*$)", + "contentName": "meta.embedded.block.odin", + "patterns": [ + { + "include": "source.odin" + } + ] + } + ] + } + }, + "scopeName": "markdown.odin.codeblock" +} -- cgit v1.2.3 From 607722dcb9624d07e9f4513bf706e24fed06c5d3 Mon Sep 17 00:00:00 2001 From: DanielGavin Date: Fri, 28 Jun 2024 23:48:34 +0200 Subject: Support specifying the os with profile. --- src/server/requests.odin | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/server/requests.odin b/src/server/requests.odin index 8af1141..0fd73ba 100644 --- a/src/server/requests.odin +++ b/src/server/requests.odin @@ -477,23 +477,22 @@ read_ols_initialize_options :: proc( ) } } + + config.profile.os = strings.clone(profile.os) + + break } } + if config.profile.os == "" { + config.profile.os = os_enum_to_string[ODIN_OS] + } + config.checker_targets = slice.clone( ols_config.checker_targets, context.allocator, ) - found_target := false - - for target in config.checker_targets { - if ODIN_OS in os_enum_to_string { - found_target = true - } - } - - config.enable_inlay_hints = ols_config.enable_inlay_hints.(bool) or_else config.enable_inlay_hints config.enable_fake_method = @@ -558,7 +557,9 @@ read_ols_initialize_options :: proc( context.temp_allocator, ) - config.collections[strings.clone(it.name)] = strings.clone(slashed_path) + config.collections[strings.clone(it.name)] = strings.clone( + slashed_path, + ) } else { log.errorf( "Failed to find absolute address of collection: %v", @@ -743,7 +744,7 @@ request_initialize :: proc( if uri, ok := common.parse_uri(project_uri, context.temp_allocator); ok { global_ols_config_path := path.join( - elems = { + elems = { filepath.dir(os.args[0], context.temp_allocator), "ols.json", }, -- cgit v1.2.3 From 68b9750acef29f53988f282f575fa18643725550 Mon Sep 17 00:00:00 2001 From: DanielGavin Date: Fri, 28 Jun 2024 23:48:52 +0200 Subject: Forgot file --- src/server/build.odin | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/server/build.odin b/src/server/build.odin index d9e052a..810c161 100644 --- a/src/server/build.odin +++ b/src/server/build.odin @@ -27,6 +27,9 @@ platform_os: map[string]bool = { "openbsd" = true, "wasi" = true, "wasm" = true, + "haiku" = true, + "netbsd" = true, + "freebsd" = true, } @@ -39,8 +42,28 @@ os_enum_to_string: map[runtime.Odin_OS_Type]string = { .WASI = "wasi", .JS = "js", .Freestanding = "freestanding", - .OpenBSD = "openbsd", .JS = "wasm", + .Haiku = "haiku", + .OpenBSD = "openbsd", + .NetBSD = "netbsd", + .FreeBSD = "freebsd", +} + +@(private = "file") +is_bsd_variant :: proc(name: string) -> bool { + return( + common.config.profile.os == os_enum_to_string[.FreeBSD] || + common.config.profile.os == os_enum_to_string[.OpenBSD] || + common.config.profile.os == os_enum_to_string[.NetBSD] \ + ) +} + +@(private = "file") +is_unix_variant :: proc(name: string) -> bool { + return( + common.config.profile.os == os_enum_to_string[.Linux] || + common.config.profile.os == os_enum_to_string[.Darwin] \ + ) } skip_file :: proc(filename: string) -> bool { @@ -50,10 +73,16 @@ skip_file :: proc(filename: string) -> bool { if last_underscore_index + 1 < last_dot_index { name_between := filename[last_underscore_index + 1:last_dot_index] + if name_between == "unix" { + return !is_unix_variant(name_between) + } + + if name_between == "bsd" { + return !is_bsd_variant(name_between) + } + if _, ok := platform_os[name_between]; ok { - if name_between != os_enum_to_string[ODIN_OS] { - return true - } + return name_between != common.config.profile.os } } -- cgit v1.2.3 From 9fc36bfa5c76bec6f890d744398169a8069ada5a Mon Sep 17 00:00:00 2001 From: DanielGavin Date: Fri, 28 Jun 2024 23:53:07 +0200 Subject: Update package --- editors/vscode/package-lock.json | 4 ++-- editors/vscode/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/editors/vscode/package-lock.json b/editors/vscode/package-lock.json index da86bd6..404d3e5 100644 --- a/editors/vscode/package-lock.json +++ b/editors/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "ols", - "version": "0.1.27", + "version": "0.1.30", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ols", - "version": "0.1.27", + "version": "0.1.30", "dependencies": { "adm-zip": "^0.5.9", "https-proxy-agent": "^5.0.0", diff --git a/editors/vscode/package.json b/editors/vscode/package.json index 66e9bc4..a017ed5 100644 --- a/editors/vscode/package.json +++ b/editors/vscode/package.json @@ -7,7 +7,7 @@ "type": "git", "url": "git://github.com/DanielGavin/ols.git" }, - "version": "0.1.27", + "version": "0.1.30", "engines": { "vscode": "^1.66.0" }, -- cgit v1.2.3