Skip to content

Commit

Permalink
Merge pull request #129 from LuqueDaniel/double-underscore-variable
Browse files Browse the repository at this point in the history
reg: version 2.0.10 changes
  • Loading branch information
LuqueDaniel authored May 29, 2022
2 parents 6c09180 + 75437c8 commit 39b0b54
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 2.0.10 (2022/05/24)

### Fixes

* Allow double underscore in variable names [#123](https://github.com/LuqueDaniel/vscode-language-renpy/pull/123) (fix issue [#122](https://github.com/LuqueDaniel/vscode-language-renpy/issues/122))

### Other changes

* Reserved variable names now show as warnings instead of errors

## 2.0.9 (2022/05/02)

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "languague-renpy",
"displayName": "Ren'Py Language",
"description": "Adds rich support for the Ren'Py programming language to Visual Studio Code.",
"version": "2.0.8",
"version": "2.0.10",
"publisher": "LuqueDaniel",
"license": "MIT",
"homepage": "https://github.com/LuqueDaniel/vscode-language-renpy",
Expand Down
25 changes: 17 additions & 8 deletions src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const rxReservedPythonCheck =
const rxObsoleteCheck =
/[\s(=]+(LiveCrop|LiveComposite|Tooltip|im\.Rotozoom|im\.ImageBase|im\.ramp|im\.Map|im\.Flip|im\.math|im\.expands_bounds|im\.threading|im\.zipfile|im\.Recolor|im\.Color|im\.io|im\.Alpha|im\.Data|im\.Image|im\.Twocolor|im\.MatrixColor|im\.free_memory|im\.Tile|im\.FactorScale|im\.Sepia|im\.Crop|im\.AlphaMask|im\.Blur|im\.tobytes|im\.matrix|im\.Grayscale|ui\.add|ui\.bar|ui\.imagebutton|ui\.input|ui\.key|ui\.label|ui\.null|ui\.text|ui\.textbutton|ui\.timer|ui\.vbar|ui\.hotspot|ui\.hotbar|ui\.spritemanager|ui\.button|ui\.frame|ui\.transform|ui\.window|ui\.drag|ui\.fixed|ui\.grid|ui\.hbox|ui\.side|ui\.vbox|ui\.imagemap|ui\.draggroup)[^a-zA-Z]/g;

const rxVariableCheck = /^\s*(default|define)\s+([^a-zA-Z\s][a-zA-Z0-9_]*)\s+=/g;
const rxVariableCheck = /^\s*(default|define)\s+([^a-zA-Z\s_][a-zA-Z0-9_]*)\s+=/g;
const rxReservedVariableCheck = /\s*(default|define)\s+(_[a-zA-Z0-9]*)\s+=/g;
const rxPersistentDefines = /^\s*(default|define)\s+persistent\.([a-zA-Z]+[a-zA-Z0-9_]*)\s*=\s*(.*$)/g;
const rxPersistentCheck = /\s+persistent\.(\w+)[^a-zA-Z]/g;
const rxStoreCheck = /\s+store\.(\w+)[^a-zA-Z_]?/g;
Expand Down Expand Up @@ -147,6 +148,7 @@ export function refreshDiagnostics(doc: TextDocument, diagnosticCollection: Diag
}

if (config.warnOnReservedVariableNames) {
checkReservedRenpyNames(diagnostics, line, lineIndex);
checkReservedPythonNames(diagnostics, line, lineIndex);
}

Expand Down Expand Up @@ -204,7 +206,18 @@ function checkComparisonVsAssignment(diagnostics: Diagnostic[], line: string, li
while ((matches = rsComparisonCheck.exec(line)) !== null) {
const offset = matches.index + matches[0].indexOf(matches[3]);
const range = new Range(lineIndex, offset, lineIndex, offset + matches[3].length);
const diagnostic = new Diagnostic(range, `"=" is the equality operator. Use "==" for comparison.`, DiagnosticSeverity.Warning);
const diagnostic = new Diagnostic(range, `"=" is the assignment operator. Use "==" for comparison.`, DiagnosticSeverity.Warning);
diagnostics.push(diagnostic);
}
}

function checkReservedRenpyNames(diagnostics: Diagnostic[], line: string, lineIndex: number) {
// check for default/define variables that are Ren'Py reserved names
let matches;
while ((matches = rxReservedVariableCheck.exec(line)) !== null) {
const offset = matches.index + matches[0].indexOf(matches[2]);
const range = new Range(lineIndex, offset, lineIndex, offset + matches[2].length);
const diagnostic = new Diagnostic(range, `"${matches[2]}": Variables may not begin with a single underscore '_' as Ren'Py reserves such variables for its own purposes.`, DiagnosticSeverity.Warning);
diagnostics.push(diagnostic);
}
}
Expand All @@ -215,7 +228,7 @@ function checkReservedPythonNames(diagnostics: Diagnostic[], line: string, lineI
while ((matches = rxReservedPythonCheck.exec(line)) !== null) {
const offset = matches.index + matches[0].indexOf(matches[2]);
const range = new Range(lineIndex, offset, lineIndex, offset + matches[2].length);
const diagnostic = new Diagnostic(range, `"${matches[2]}" is a Python reserved name, type, or function. Using it as a variable can lead to obscure problems or unpredictable behavior.`, DiagnosticSeverity.Error);
const diagnostic = new Diagnostic(range, `"${matches[2]}": is a Python reserved name, type, or function. Using it as a variable can lead to obscure problems or unpredictable behavior.`, DiagnosticSeverity.Warning);
diagnostics.push(diagnostic);
}
}
Expand All @@ -238,11 +251,7 @@ function checkInvalidVariableNames(diagnostics: Diagnostic[], line: string, line
if (!renpyStore.includes(matches[2])) {
const offset = matches.index + matches[0].indexOf(matches[2]);
const range = new Range(lineIndex, offset, lineIndex, offset + matches[2].length);
const diagnostic = new Diagnostic(
range,
`"${matches[2]}": Variables must begin with a letter (and may contain numbers, letters, or underscores). Variables may not begin with '_' as Ren'Py reserves such variables for its own purposes.`,
severity
);
const diagnostic = new Diagnostic(range, `"${matches[2]}": Variables must begin with a letter (and may contain numbers, letters, or underscores).`, severity);
diagnostics.push(diagnostic);
}
}
Expand Down

0 comments on commit 39b0b54

Please sign in to comment.