diff --git a/.gitignore b/.gitignore index abccec3..1c714cc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ node_modules server publish/*.vsix test -configrations/tmp.txt -configrations/test.py \ No newline at end of file +*.vsix +configurations/tmp.txt +configurations/test.py diff --git a/.vscode/launch.json b/.vscode/launch.json index c77b2ad..c5190fd 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "args": ["--extensionDevelopmentPath=${workspaceRoot}" ], "stopOnEntry": false, "sourceMaps": true, - "outDir": "${workspaceRoot}/out/src", + "outFiles": ["${workspaceRoot}/out/src"], "preLaunchTask": "npm" }, { @@ -21,7 +21,7 @@ "args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ], "stopOnEntry": false, "sourceMaps": true, - "outDir": "${workspaceRoot}/out/test", + "outFiles": ["${workspaceRoot}/out/test"], "preLaunchTask": "npm" } ] diff --git a/.vscode/tasks.json b/.vscode/tasks.json index fb7f662..1e37eb7 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -23,7 +23,7 @@ "args": ["run", "compile", "--loglevel", "silent"], // The tsc compiler is started in watching mode - "isWatching": true, + "isBackground": true, // use the standard tsc in watch mode problem matcher to find compile problems in the output. "problemMatcher": "$tsc-watch" diff --git a/configrations/GDScript.full.tmLanguage.json b/configurations/GDScript.full.tmLanguage.json similarity index 98% rename from configrations/GDScript.full.tmLanguage.json rename to configurations/GDScript.full.tmLanguage.json index b3e0ca4..a456721 100644 --- a/configrations/GDScript.full.tmLanguage.json +++ b/configurations/GDScript.full.tmLanguage.json @@ -9,8 +9,15 @@ { "include": "#numbers" }, { "include": "#self" }, { + "captures": + { + "1": + { + "name": "punctuation.definition.comment.number-sign.gdscript" + } + }, "match": "(#).*$\\n?", - "name": "punctuation.definition.comment.gdscript" + "name": "comment.line.number-sign.gdscript" }, { "match": "\\b(?i:elif|else|for|if|while|break|continue|pass|and|in|is|not|or|return|onready|setget|breakpoint)\\b", diff --git a/configrations/GDScript.tmLanguage.json b/configurations/GDScript.tmLanguage.json similarity index 98% rename from configrations/GDScript.tmLanguage.json rename to configurations/GDScript.tmLanguage.json index f2cc26c..743d8c7 100644 --- a/configrations/GDScript.tmLanguage.json +++ b/configurations/GDScript.tmLanguage.json @@ -9,8 +9,15 @@ { "include": "#numbers" }, { "include": "#self" }, { + "captures": + { + "1": + { + "name": "punctuation.definition.comment.number-sign.gdscript" + } + }, "match": "(#).*$\\n?", - "name": "punctuation.definition.comment.gdscript" + "name": "comment.line.number-sign.gdscript" }, { "match": "\\b(?i:elif|else|for|if|while|break|continue|pass|and|in|is|not|or|return|onready|setget|breakpoint)\\b", diff --git a/configrations/gdscript-configuration.json b/configurations/gdscript-configuration.json similarity index 100% rename from configrations/gdscript-configuration.json rename to configurations/gdscript-configuration.json diff --git a/configrations/snippets.json b/configurations/snippets.json similarity index 100% rename from configrations/snippets.json rename to configurations/snippets.json diff --git a/package.json b/package.json index 4c8c8ac..f6d4017 100644 --- a/package.json +++ b/package.json @@ -73,20 +73,20 @@ "extensions": [ ".gd" ], - "configuration": "./configrations/gdscript-configuration.json" + "configuration": "./configurations/gdscript-configuration.json" } ], "grammars": [ { "language": "gdscript", "scopeName": "source.gdscript", - "path": "./configrations/GDScript.tmLanguage.json" + "path": "./configurations/GDScript.tmLanguage.json" } ], "snippets": [ { "language": "gdscript", - "path": "./configrations/snippets.json" + "path": "./configurations/snippets.json" } ], "breakpoints": [ diff --git a/src/gdscript/diagnostic.ts b/src/gdscript/diagnostic.ts index 2f7ac2f..62014f4 100644 --- a/src/gdscript/diagnostic.ts +++ b/src/gdscript/diagnostic.ts @@ -57,13 +57,11 @@ class GDScriptDiagnosticSeverity { private validateUnusedSymbols(doc: vscode.TextDocument,script) { let diagnostics = []; - const text = doc.getText(); + const text = doc.getText().replace(new RegExp(/#.*$/, "gm"), ""); //excludes comments from being checked for syntax const check = (name:string, range: vscode.Range) => { var matchs = text.match(new RegExp(`[^0-9A-Za-z_]\\s*${name}[^0-9A-Za-z_]\\s*`, 'g')); let count = matchs?matchs.length:0; - var incomment = text.match(new RegExp(`#[^0-9A-z_]*${name}[^0-9A-z_]`, 'g')); - count -= incomment?incomment.length:0; if(count <= 1) diagnostics.push(new vscode.Diagnostic(range, `${name} is never used.`, DiagnosticSeverity.Warning)); }; @@ -77,7 +75,7 @@ class GDScriptDiagnosticSeverity { private validateExpression(doc: vscode.TextDocument) { let diagnostics = []; - const text = doc.getText(); + const text = doc.getText().replace(new RegExp(/#.*$/, "gm"), ""); //excludes comments from being checked for syntax const lines = text.split(/\r?\n/); lines.map((line:string, i: number) =>{ let matchstart = /[^\s]+.*/.exec(line); @@ -104,12 +102,18 @@ class GDScriptDiagnosticSeverity { diagnostics.push(new vscode.Diagnostic(range, "Extra brackets in condition expression.", DiagnosticSeverity.Warning)); if( i < lines.length-1) { - const nextline = lines[i+1]; + let next = i+1; + let nextline = lines[next]; + while (!nextline || /\s+$/gm.test(nextline) && next < lines.length-1) //changes nextline until finds a line containg text or comes to the last line + { + nextline = lines[next]; + ++next; + } let nextLineStartAt = -1; let match = /[^\s]+.*/.exec(nextline); if(match) nextLineStartAt = match.index; - + if(nextLineStartAt <= curLineStartAt) diagnostics.push(new vscode.Diagnostic(range, "Expected indented block after expression", DiagnosticSeverity.Error)); } diff --git a/test_files/0.2.2/test.gd b/test_files/0.2.2/test.gd new file mode 100644 index 0000000..758b9e3 --- /dev/null +++ b/test_files/0.2.2/test.gd @@ -0,0 +1,64 @@ +#Highlights syntax highglighting issues in godot-tools release 0.2.2 + +extends Node + +# class member variables go here, for example: +#var a = 2 +# var b = "textvar" + +#func read(): #in 0.2.2, false positive +# var path = "res://assets/instructions.toml" +# var file = File.new() +# file.open(path, file.READ) +# +#func _ready(): #in 0.2.2 false positive +# # Called every time the node is added to the scene. +# # Initialization here +# read() + +func remove_ends(text): #in 0.2.2 false positive +#vasdfs + var result = "result" #hello + result = result.replace("[", "") + result = result.replace("]", "") + return result + +func read_cfg(path): #in 0.2.2 false positive + + var config = ConfigFile.new() + var err = config.load(path) + + var sections = {} + if err == OK: # if not, something went wrong with the file loading + # Look for the display/width pair, and default to 1024 if missing +# #var screen_width = get_value("display", "width", 1024) #in 0.2.2 false positive +# # Store a variable if and only it hasn't been defined yet +# if not config.has_section_key("audio", "mute"): +# config.set_value("audio", "mute", false) +# # Save the changes by overwriting the previous file +# config.save("user://settings.cfg" + for i in config.get_sections(): + var section_pairs = {} + for j in config.get_section_keys(i): + section_pairs[j] = config.get_value(i, j) + sections[i] = section_pairs + print(sections) + return sections + +func something(): #in 0.2.2 diagnostics correctly complains +asdfsdd + +asdfsdf +asdf +func somethingelse(): #in 0.2.2 correctly doesn't complain + asdfsd + +asdfsd #in 0.2.2 should complain? + +func something_else(): + var asds = 2 #in 0.2.2 diagnostics should complain + asdfsdaf s = 3 #in 0.2.2 diagnostics should complain + return 3 + +func yet_else(): + pass \ No newline at end of file diff --git a/test_files/0.2.2/test2.gd b/test_files/0.2.2/test2.gd new file mode 100644 index 0000000..e6240d3 --- /dev/null +++ b/test_files/0.2.2/test2.gd @@ -0,0 +1,5 @@ +#func read(): +#func read(): #in 0.2.2, false positive +# func read(): #in 0.2.2, not false positive +#func +#var a = 0 \ No newline at end of file