mirror of
https://github.com/godotengine/godot-vscode-plugin.git
synced 2025-12-31 13:48:24 +03:00
Fixes for gdscript syntax checking (#7)
* Fixed the typo in the folder name configrations Now the name is configurations. All the code referencing the folder has also been updated. * Updated deprecated variables * Demonstration of current diagnostics issues All the lines that get a complaint from diagnostics are marked with #in 0.2.2 and a short explanation whether the complaint is valid or not. * Enabled syntax highlighting for comments Now comments have a different colour compared to variables. Found it unclear which file controls syntax so edited both GDScript.full.tmLanguage.json and GDScript.tmLanguage.json. In addition renamed test_files directory to be clearer and started working on diagnostic.ts to fix false positives in syntax highglighting. * Fixed checking comments for syntax Now comments are not checked for syntax. This was achieved by excluding comments from being parsed. In addition made it so that syntax check no longer complains about empty lines having wrong indentation. * Wrong committer details on previous commits This commit should have the correct details. * Added a comment explaining how nextline is parsed * Reverted changes in symbolparser.ts Also made minor additions to test_files.
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -3,5 +3,6 @@ node_modules
|
||||
server
|
||||
publish/*.vsix
|
||||
test
|
||||
configrations/tmp.txt
|
||||
configrations/test.py
|
||||
*.vsix
|
||||
configurations/tmp.txt
|
||||
configurations/test.py
|
||||
|
||||
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
@@ -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"
|
||||
}
|
||||
]
|
||||
|
||||
2
.vscode/tasks.json
vendored
2
.vscode/tasks.json
vendored
@@ -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"
|
||||
|
||||
@@ -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",
|
||||
@@ -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",
|
||||
@@ -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": [
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
64
test_files/0.2.2/test.gd
Normal file
64
test_files/0.2.2/test.gd
Normal file
@@ -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
|
||||
5
test_files/0.2.2/test2.gd
Normal file
5
test_files/0.2.2/test2.gd
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user