diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2024-06-28 23:54:10 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2024-06-28 23:54:10 +0200 |
| commit | 28f666c77352734ee720b3b56e34f7261d3a86b2 (patch) | |
| tree | b90802760959cae5d80004a874d3df5011a6c2f6 | |
| parent | f2dd4753508299f86490c083cf4eaad0c8ab7b1e (diff) | |
| parent | 9fc36bfa5c76bec6f890d744398169a8069ada5a (diff) | |
Merge branch 'master' into rename
| -rw-r--r-- | editors/vscode/package-lock.json | 4 | ||||
| -rw-r--r-- | editors/vscode/package.json | 12 | ||||
| -rw-r--r-- | editors/vscode/syntaxes/codeblock.json | 45 | ||||
| -rw-r--r-- | editors/vscode/syntaxes/odin.tmLanguage.json | 121 | ||||
| -rw-r--r-- | src/odin/printer/visit.odin | 7 | ||||
| -rw-r--r-- | src/server/build.odin | 37 | ||||
| -rw-r--r-- | src/server/completion.odin | 60 | ||||
| -rw-r--r-- | src/server/requests.odin | 17 |
8 files changed, 220 insertions, 83 deletions
diff --git a/editors/vscode/package-lock.json b/editors/vscode/package-lock.json index 26b64a9..2384838 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 021a214..e7d0003 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.29", + "version": "0.1.30", "engines": { "vscode": "^1.66.0" }, @@ -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" +} diff --git a/editors/vscode/syntaxes/odin.tmLanguage.json b/editors/vscode/syntaxes/odin.tmLanguage.json index d9349b9..6f44764 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" } ] @@ -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,21 +384,12 @@ "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": [ { - "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" }, @@ -435,7 +421,7 @@ "match": "\\b(auto_cast|distinct|using)\\b" }, { - "name": "variable.other.object.odin", + "name": "keyword.context.odin", "match": "\\b(context)\\b" }, { @@ -463,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", @@ -500,10 +494,10 @@ }, { "name": "keyword.operator.odin", - "match": "@|(\\||\\!|:|\\+|-|\\*|/|%|\\<\\<?|\\>\\>?|\\~)=?|=|: : ?|\\.\\.|\\$" + "match": "@|(\\||\\!|:|\\+|-|\\*|/|%|\\<\\<?|\\>\\>?|\\~)=?|=|: : ?|\\$" }, { - "name": "keyword.other.odin", + "name": "entity.name.tag.odin", "match": "#[A-Za-z_]\\w*" } ] @@ -570,34 +564,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 +606,8 @@ ] }, "punctuation": { - "patterns": [ - { - "name": "punctuation.odin", - "match": "\\(|\\)|\\{|\\}|;|\\[|\\]|\\.|," - } - ] + "name": "punctuation.odin", + "match": "\\(|\\)|\\{|\\}|;|\\[|\\]|\\.|,|\\\\" } }, "scopeName": "source.odin" 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, diff --git a/src/server/build.odin b/src/server/build.odin index f06f64e..312cb00 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 } } diff --git a/src/server/completion.odin b/src/server/completion.odin index a863d5c..42bec3e 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -1999,6 +1999,66 @@ 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 + } + + 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 + { + item := CompletionItem { + label = "pop", + kind = .Function, + detail = "pop", + textEdit = TextEdit { + newText = fmt.tprintf("pop(%v)", ptr_symbol_str), + 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, ptr_symbol_str), + range = {start = range.end, end = range.end}, + }, + insertTextFormat = .Snippet, + InsertTextMode = .adjustIndentation, + } + + append(items, item) + } } append_magic_union_completion :: proc( diff --git a/src/server/requests.odin b/src/server/requests.odin index 3d0991f..b47c4a0 100644 --- a/src/server/requests.odin +++ b/src/server/requests.odin @@ -478,23 +478,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 = |