From 07ccecfbd8149a78b8b91018712c19b0f194d319 Mon Sep 17 00:00:00 2001 From: RedCMD Date: Tue, 8 Oct 2024 21:55:54 +1300 Subject: [PATCH] Improve error handling --- README.md | 1 - src/Providers/CodeActionsProvider.ts | 2 +- src/tree-sitter/tree-sitter-json/grammar.js | 18 ++-- syntaxes/regex.tmLanguage.json | 91 ++++++++++----------- 4 files changed, 53 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 573bdc9..3dadae6 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,6 @@ Highlights scope names with their own themed colour in realtime: ### Todo * Support unicode character insertions `\u00b0` -* Unify ways of displaying errors * Improve performance: [Github Issue - Capturing and applying a pattern causes performance loss](https://github.com/microsoft/vscode-textmate/issues/167) * Finish ctrl+click definitions and references * Add hovers diff --git a/src/Providers/CodeActionsProvider.ts b/src/Providers/CodeActionsProvider.ts index 078a789..15a7239 100644 --- a/src/Providers/CodeActionsProvider.ts +++ b/src/Providers/CodeActionsProvider.ts @@ -43,7 +43,7 @@ export const CodeActionsProvider: vscode.CodeActionProvider = { }; break; case 'missing': - const missing = message.split("'")[3]; + const missing = message.split("'")[3] || "'"; edit.insert(document.uri, diagnostic.range.end, missing); codeAction = { diff --git a/src/tree-sitter/tree-sitter-json/grammar.js b/src/tree-sitter/tree-sitter-json/grammar.js index a02e5f5..2450ad6 100644 --- a/src/tree-sitter/tree-sitter-json/grammar.js +++ b/src/tree-sitter/tree-sitter-json/grammar.js @@ -503,7 +503,7 @@ module.exports = grammar({ "true", "false", ), - null: $ => /null/, + null: $ => "null", integer: $ => /-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/, _string: $ => token( prec(-1, @@ -615,17 +615,13 @@ function pair($, key, value) { ), ), ), + $._colon, + repeat($._whitespace), optional( - seq( - $._colon, - repeat($._whitespace), - optional( // TS bad at error recovery - choice( - value ?? blank(), - prec(-2, - $._value, - ), - ), + choice( + value ?? blank(), + prec(-2, + $._value, ), ), ), diff --git a/syntaxes/regex.tmLanguage.json b/syntaxes/regex.tmLanguage.json index 915f9c5..3586501 100644 --- a/syntaxes/regex.tmLanguage.json +++ b/syntaxes/regex.tmLanguage.json @@ -149,21 +149,21 @@ "capture-group": { "comment": "( ... )", "begin": "\\(", - "end": "\\)", + "end": "\\)|(?=\")", "captures": { "0": { "name": "constant.character.set.regexp.tm strong" } }, "patterns": [ { "include": "$self" } ] }, "capture-group-extended": { "comment": "( ... )", "begin": "\\(", - "end": "\\)", + "end": "\\)|(?=\")", "captures": { "0": { "name": "constant.character.set.regexp.tm strong" } }, "patterns": [ { "include": "#$self-extended" } ] }, "non-capture-group": { "comment": "(?:...) (?>...)", "begin": "(\\()(\\?[:>])", - "end": "\\)", + "end": "\\)|(?=\")", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm" }, "2": { "name": "support.function.tm regex" } @@ -174,7 +174,7 @@ "non-capture-group-extended": { "comment": "(?:...) (?>...)", "begin": "(\\()(\\?[:>])", - "end": "\\)", + "end": "\\)|(?=\")", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm" }, "2": { "name": "support.function.tm regex" } @@ -185,7 +185,7 @@ "capture-group-lookahead": { "comment": "(?=...) (?!...)", "begin": "(\\()(\\?[!=])", - "end": "(\\))([+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?", + "end": "(\\))([+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?|(?=\")", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm markup.italic" }, "2": { "name": "support.function.tm" } @@ -199,7 +199,7 @@ "capture-group-lookahead-extended": { "comment": "(?=...) (?!...)", "begin": "(\\()(\\?[!=])", - "end": "(\\))([+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?", + "end": "(\\))([+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?|(?=\")", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm markup.italic" }, "2": { "name": "support.function.tm" } @@ -213,7 +213,7 @@ "capture-group-lookbehind": { "comment": "(?<=...)", "begin": "(\\()(\\?<=)", - "end": "(\\))([+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?", + "end": "(\\))([+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?|(?=\")", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm markup.italic" }, "2": { "name": "support.function.tm regex" } @@ -232,7 +232,7 @@ "capture-group-lookbehind-extended": { "comment": "(?<=...)", "begin": "(\\()(\\?<=)", - "end": "(\\))([+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?", + "end": "(\\))([+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?|(?=\")", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm markup.italic" }, "2": { "name": "support.function.tm regex" } @@ -251,7 +251,7 @@ "capture-group-lookbehind-invalid": { "comment": "(?=...)? (?!...)+ (?[+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?", + "end": "\\)(?>[+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?|(?=\")", "captures": { "0": { "name": "invalid.illegal.tm markup.underline" }, "1": { "name": "regex" } @@ -265,7 +265,7 @@ "capture-group-lookbehind-invalid-extended": { "comment": "(?=...)? (?!...)+ (?[+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?", + "end": "\\)(?>[+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?|(?=\")", "captures": { "0": { "name": "invalid.illegal.tm markup.underline" }, "1": { "name": "regex" } @@ -279,7 +279,7 @@ "capture-group-negative-lookbehind": { "comment": "(?\\d+,?\\d*|,\\d+)})?", + "end": "(\\))([+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?|(?=\")", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm markup.italic" }, "2": { "name": "support.function.tm regex" } @@ -298,7 +298,7 @@ "capture-group-negative-lookbehind-extended": { "comment": "(?\\d+,?\\d*|,\\d+)})?", + "end": "(\\))([+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?|(?=\")", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm markup.italic" }, "2": { "name": "support.function.tm regex" } @@ -319,14 +319,14 @@ { "comment": "(?=...)? (?!...){2,3}", "begin": "\\(\\?[!=]", - "end": "\\)(?>[+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?", + "end": "\\)(?>[+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?|(?=\")", "captures": { "0": { "name": "invalid.illegal.tm markup.underline" } }, "patterns": [ { "include": "$self" } ] }, { "comment": "(...)", "begin": "\\((?!\\?[-~<=:!{|IimxWDSPy]|\\*[A-Za-z_])", - "end": "\\)", + "end": "\\)|(?=\")", "captures": { "0": { "name": "invalid.illegal.tm markup.underline" } }, "patterns": [ { "include": "#capture-group-negative-lookbehind-invalid-extended" }, @@ -341,7 +341,7 @@ { "comment": "(?=...)? (?!...){2,3}", "begin": "\\(\\?[!=]", - "end": "\\)(?>[+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?", + "end": "\\)(?>[+*?]|(?D){(?>\\d+,?\\d*|,\\d+)})?|(?=\")", "captures": { "0": { "name": "invalid.illegal.tm markup.underline" } }, "patterns": [ { "include": "#capture-group-negative-lookbehind-invalid-extended" }, @@ -352,7 +352,7 @@ { "comment": "(...)", "begin": "\\((?!\\?[-~<=:!{|IimxWDSPy]|\\*[A-Za-z_])", - "end": "\\)", + "end": "\\)|(?=\")", "captures": { "0": { "name": "invalid.illegal.tm markup.underline" } }, "patterns": [ { "include": "#capture-group-negative-lookbehind-invalid-extended" }, @@ -381,7 +381,7 @@ "patterns": [ { "begin": "\\G", - "end": "(?=[):])", + "end": "(?=[):\"])", "patterns": [ { "match": "I(?=[^-I:)]*I)", @@ -425,7 +425,7 @@ { "comment": "(?y{g}-imxWDSP) (?y{w}imxWDSP-x: ...)", "begin": "(?>(\\((?=[^:)]+:))|(\\())(\\?)(?=[-IimxWDSPy])(?=[^x:)]++[:)]|[^-:)]*+-[^x:)]*+x[^:)]*+[:)])", - "end": "(?((?!\\1))\\)|(?=[\")]))(?#Condition is true only when Backreference \\1 from capture group 1 in \"begin\" is *not* empty.)", + "end": "(?((?!\\1))\\)|(?=[\")]))(?#Condition is true only when Backreference \\1 from capture group 1 in \"begin\" is *not* empty.)|(?=\")", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm" }, "2": { "name": "constant.character.set.regexp.tm markup.italic" }, @@ -468,7 +468,7 @@ "patterns": [ { "begin": "\\G", - "end": "(:)|(\\))", + "end": "(:)|(\\))|(?=\")", "endCaptures": { "1": { "name": "support.function.tm" }, "2": { "name": "constant.character.set.regexp.tm markup.italic" } @@ -491,7 +491,7 @@ "patterns": [ { "begin": "\\G", - "end": "\\)", + "end": "\\)|(?=\")", "endCaptures": { "0": { "name": "constant.character.set.regexp.tm" } }, "patterns": [ { "include": "#$self-extended" } ] }, @@ -509,7 +509,7 @@ { "comment": "(?y{g}imxWDSP-) (?y{w}x-imWDSP:...)", "begin": "(?>(\\((?=[^:)]+:))|(\\())(\\?)(?=[-IimxWDSPy])(?=[^-:)]*+[^x:)]*+[:)])", - "end": "(?((?!\\1))\\)|(?=[\")]))(?#Condition is true only when Backreference \\1 from capture group 1 in \"begin\" is *not* empty.)", + "end": "(?((?!\\1))\\)|(?=[\")]))(?#Condition is true only when Backreference \\1 from capture group 1 in \"begin\" is *not* empty.)|(?=\")", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm" }, "2": { "name": "constant.character.set.regexp.tm markup.italic" }, @@ -520,7 +520,7 @@ "patterns": [ { "begin": "\\G", - "end": "(:)|(\\))", + "end": "(:)|(\\))|(?=\")", "endCaptures": { "1": { "name": "support.function.tm" }, "2": { "name": "constant.character.set.regexp.tm markup.italic" } @@ -541,7 +541,7 @@ }, { "begin": "-", - "end": "(?=[:)])", + "end": "(?=[:)\"])", "beginCaptures": { "0": { "name": "support.function.tm" } }, "patterns": [ { @@ -570,7 +570,7 @@ { "comment": "(?(1)...|...) (?(-001)...) (?(1+0)...|...) (?(<1>)...) (?('+1')...|...) (?(<1-0>)...) (?()...) (?('name-0')...|...) (?()...) (?(...)...|...) (?(?{...})...|...) (?(*FAIL)|...)", "begin": "(?D)(\\()(\\?)(?>(\\()(?>(<|(?'))(?>(?>(?[+-]?(0*)(?>[1-9]\\d{,2}(\\d*)|(0)))|(\\w+))((?~(?()'|>)|[)+-]))(?[+-](0*)(?2(?>0\\d{8}|1(?>[0-3]\\d{7}|4(?>[0-6]\\d{6}|7(?>[0-3]\\d{5}|4(?>[0-7]\\d{4}|8(?>[0-2]\\d{3}|3(?>[0-5]\\d{2}|6(?>[0-3]\\d|4[0-7]))))))))|1?\\d{1,9}))?)?((?~(?()'|>)|\\)))((?()'|>))?([^)]*)|(?=(?>[+-](?=0*[1-9]))?0*\\g\\b)\\g\\g?)(\\))|(?=\\((?>\\?{|\\*))|(\\())", - "end": "(?)...) (?('+1')...|...) (?(<1-0>)...) (?()...) (?('name-0')...|...) (?()...) (?(...)...|...) (?(?{...})...|...) (?(*FAIL)|...)", "begin": "(?D)(\\()(\\?)(?>(\\()(?>(<|(?'))(?>(?>(?[+-]?(0*)(?>[1-9]\\d{,2}(\\d*)|(0)))|(\\w+))((?~(?()'|>)|[)+-]))(?[+-](0*)(?2(?>0\\d{8}|1(?>[0-3]\\d{7}|4(?>[0-6]\\d{6}|7(?>[0-3]\\d{5}|4(?>[0-7]\\d{4}|8(?>[0-2]\\d{3}|3(?>[0-5]\\d{2}|6(?>[0-3]\\d|4[0-7]))))))))|1?\\d{1,9}))?)?((?~(?()'|>)|\\)))((?()'|>))?([^)]*)|(?=(?>[+-](?=0*[1-9]))?0*\\g\\b)\\g\\g?)(\\))|(?=\\((?>\\?{|\\*))|(\\())", - "end": "(?...) (?'name'...)", "begin": "(\\()(\\?)(<|(?'))(?=((?()'|>))?)", - "end": "\\)", + "end": "\\)|(?=\")", "name": "capture-group-name", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm strong" }, @@ -675,7 +675,7 @@ "capture-group-name-extended": { "comment": "(?...) (?'name'...)", "begin": "(\\()(\\?)(<|(?'))(?=((?()'|>))?)", - "end": "\\)", + "end": "\\)|(?=\")", "name": "capture-group-name", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm strong" }, @@ -692,7 +692,7 @@ "capture-group-name-name": { "comment": "_name;0%>", "begin": "(?<=(?'bracket'<)|')\\G((?~[\\w)\"&&[^0-9]]|(?('bracket')>|')))", - "end": "(\\\\(?>u\\h{,3})?)?((?((?!\\1))>|'))|(?=(\"|\\)))", + "end": "(\\\\(?>u\\h{,3})?)?((?((?!\\1))>|'))|(?=([)\"]))", "beginCaptures": { "2": { "name": "invalid.illegal.tm markup.underline regex" } }, "endCaptures": { "1": { "name": "invalid.illegal.tm markup.underline" }, @@ -705,7 +705,7 @@ "capture-group-comment": { "comment": "(?#...)", "begin": "(\\()(\\?#)(?#comment)", - "end": "\\)", + "end": "\\)|(?=\")", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm markup.italic" }, "2": { "name": "support.function.tm" } @@ -723,7 +723,7 @@ "absent": { "comment": "(?~|...|...) (?~|...) (?~...)", "begin": "(\\()(\\?~\\|?)", - "end": "\\)", + "end": "\\)|(?=\")", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm" }, "2": { "name": "support.function.tm" } @@ -732,7 +732,7 @@ "patterns": [ { "begin": "(?<=\\|)\\G", - "end": "\\||(?=\\))", + "end": "\\||(?=[)\"])", "endCaptures": { "0": { "name": "support.function.tm" } }, "patterns": [ { "include": "$self" } ] }, @@ -742,7 +742,7 @@ "absent-extended": { "comment": "(?~|...|...) (?~...)", "begin": "(\\()(\\?~\\|?)", - "end": "\\)", + "end": "\\)|(?=\")", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm" }, "2": { "name": "support.function.tm" } @@ -751,7 +751,7 @@ "patterns": [ { "begin": "(?<=\\|)\\G", - "end": "\\|", + "end": "\\||(?=\")", "endCaptures": { "0": { "name": "support.function.tm" } }, "patterns": [ { "include": "#$self-extended" } ] }, @@ -761,7 +761,7 @@ "absent-invalid": { "comment": "(?~|...|...) (?~|...) (?~|)", "begin": "(\\()(\\?~\\|)", - "end": "(?!\\G)\\)|(?<=\\))", + "end": "(?!\\G)\\)|(?<=\\))|(?=\")", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm" }, "2": { "name": "support.function.tm" } @@ -770,7 +770,7 @@ "patterns": [ { "begin": "\\G", - "end": "(\\|)|(\\))", + "end": "(\\|)|(\\))|(?=\")", "endCaptures": { "1": { "name": "support.function.tm" }, "2": { "name": "invalid.illegal.tm markup.underline" } @@ -783,7 +783,7 @@ "absent-invalid-extended": { "comment": "(?~|...|...) (?~|...) (?~|)", "begin": "(\\()(\\?~\\|)", - "end": "(?!\\G)\\)|(?<=\\))", + "end": "(?!\\G)\\)|(?<=\\))|(?=\")", "beginCaptures": { "1": { "name": "constant.character.set.regexp.tm" }, "2": { "name": "support.function.tm" } @@ -792,7 +792,7 @@ "patterns": [ { "begin": "\\G", - "end": "(\\|)|(\\))", + "end": "(\\|)|(\\))|(?=\")", "endCaptures": { "1": { "name": "support.function.tm" }, "2": { "name": "invalid.illegal.tm markup.underline" } @@ -877,7 +877,7 @@ "character-class": { "comment": "[...] [^...]", "begin": "(\\[)(\\^)?", - "end": "(?!\\G)]", + "end": "(?!\\G)]|(?=\")", "beginCaptures": { "1": { "name": "support.class.tm" }, "2": { "name": "support.function.tm strong" } @@ -1114,7 +1114,7 @@ { "comment": "[:...:] [:^...:]", "begin": "\\[:\\^?(?=[^]:]{,20}(? \\g'+999' \\g<-0065535> \\g'name_123' \\g<_\\#°$\u00b0% ^&(\"'[0-9]>", "begin": "(?D)(\\\\{2}g)((?<)|')(?=((?()>|'))?)((?~\\w|[-+]0*[1-9]|\"|(?()>|')))(?>([-+]?(0*)[1-9]\\d{,2}(\\d{,2}(\\d*))|(0*)0)((?~\"|(?()>|'))))?", - "end": "(\\\\(?>u\\h{,3})?)?((?((?!\\3))>|'))|(?=(\"))", + "end": "(\\\\(?>u\\h{,3})?)?((?((?!\\3))>|'))|(?=\")", "name": "subroutine", "beginCaptures": { "1": { "name": "string.regexp.tm" }, @@ -1439,8 +1439,7 @@ }, "endCaptures": { "1": { "name": "invalid.illegal.tm markup.underline" }, - "2": { "name": "constant.character.set.regexp.tm" }, - "3": { "name": "invalid.illegal.tm markup.strikethrough" } + "2": { "name": "constant.character.set.regexp.tm" } }, "contentName": "markup.bold regex", "patterns": [ { "include": "source.json.textmate#escape-characters" } ]