Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various bug fixes and improvements #414

Merged
merged 28 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2a0baeb
Conditionals support full python expressions
duckdoom4 Jul 9, 2024
3e3b7b1
Fix crash on syntax error
duckdoom4 Jul 10, 2024
8d01b41
Add contributing tips
duckdoom4 Jul 10, 2024
ff6145a
Add more edge cases in unit test
duckdoom4 Jul 10, 2024
5a91b13
Image also supports `with`
duckdoom4 Jul 10, 2024
a57a738
Add missing keywords in screen language
duckdoom4 Jul 10, 2024
260170f
Fix screen atl missing the variable matcher
duckdoom4 Jul 10, 2024
9c335bd
Fix at,as,behind,onlayer,with not working if more then one is used
duckdoom4 Jul 10, 2024
90b7216
Add hide statement
duckdoom4 Jul 10, 2024
b102be7
Add window show/hide
duckdoom4 Jul 10, 2024
16e55c0
Add block testers to simplify the code
duckdoom4 Jul 10, 2024
0eabab7
Fix ATL on statement being tested too late
duckdoom4 Jul 10, 2024
39fb78c
Remove some useless whitespace testing
duckdoom4 Jul 10, 2024
2c225c7
Merge atl blocks into statements patterns
duckdoom4 Jul 10, 2024
e071ae0
Refactor Stack to be based on Vector
duckdoom4 Jun 10, 2023
40308be
Allow unused variables
duckdoom4 Jul 10, 2024
32970d0
Rename `tokenType` to `type`
duckdoom4 Jul 10, 2024
5445020
Update vector code
duckdoom4 Jul 10, 2024
82bad45
Token enum changes
duckdoom4 Jul 10, 2024
5944957
Add new API for Tokenizer
duckdoom4 Jul 10, 2024
cdffb01
Import changes from parser branch
duckdoom4 Jul 10, 2024
3d60ba3
Hide crashes during `Initializing Ren'Py static data` phase
duckdoom4 Jul 10, 2024
03988de
Update generated token patterns and fixes for them
duckdoom4 Jul 10, 2024
ceae313
Ignore error for now
duckdoom4 Jul 10, 2024
102fe3a
Fix some typos
duckdoom4 Jul 10, 2024
0b10943
Merge branch 'develop' into various-bug-fixes
duckdoom4 Jul 10, 2024
c5ff34c
Fix `OddFunctionCall` meta token getting generated
duckdoom4 Jul 10, 2024
7b9b08d
Fix formatting issues
duckdoom4 Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@typescript-eslint/no-var-requires": "warn",
"no-param-reassign": "warn", // Disable reassign, since this basically means you override the reference from the caller function with a new local version. (It doesn't do what you expect)
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/ban-ts-comment": "off"
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-unused-vars": "off"
}
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
"javascript",
"typescript"
],
"cSpell.words": [
"Ren'Py",
"rpyc",
"Uncompiled"
]
"editor.tokenColorCustomizations": {
"[*Light*]": {
"textMateRules": [
Expand Down
22 changes: 22 additions & 0 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ If you want to add new features, please make sure to discuss it in an issue.
5. Make your changes and submit a pull request with `develop` as your target branch
6. Happy coding! 🚀

Tips:

If you're working on syntax features, add the following textmate rule to your vscode `settings.json` file:

```json
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "debug.invalid.illegal.unmatched.renpy",
"settings": {
"foreground": "#f00"
}
},
}
```

This will make any unmatched tokens red.

Use ctrl+alt+shift+i to display the vscode build-in token debug information.

https://regexr.com will be your new best friend.

## Additional Information

### Extension Versions
Expand Down
2 changes: 1 addition & 1 deletion examples/game/script.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ label start:

# These display lines of dialogue.

e "You've created a new Ren'Py game."
character.e "You've created a new Ren'Py game."

# call a label

Expand Down
20 changes: 18 additions & 2 deletions examples/unit_test.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@

call .subroutine(2) from test #lol

call screen start #lol
call expression "sub" + "routine" pass (count=3) #lol
call expression "sub" + "routine" pass (count=3) from _class test #lol

Expand Down Expand Up @@ -547,11 +548,11 @@
show bg washington
with None

show eileen happy at left
show eileen happy at left #test
show lucy mad at right
with dissolve

show eileen happy at left with dissolve
show eileen happy with dissolve at left
show lucy mad at right with dissolve

with None
Expand Down Expand Up @@ -625,6 +626,8 @@
pass
"Fly above." if drank_tea:
pass
"Dig below." if len(my_var) >= 2:
pass

default menuset = set()

Expand Down Expand Up @@ -1566,6 +1569,19 @@
@renpy.atl_warper
def linear(t):
return t

init python:
@dataclass
class LatLonPair:
lon: float,
lat: float

@dataclass
class SimpleWeatherInfo:
id: int,
main: str,
description: str,
icon: str

label start:
show eileen happy at a, b, c
Expand Down
2 changes: 1 addition & 1 deletion src/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export async function injectCustomColorStyles(document: TextDocument) {
// Disabled until filter is added to the tree class
const documentTokens = await Tokenizer.tokenizeDocument(document);
// TODO: Should probably make sure this constant is actually part of a tag, but for now this is fine.
const colorTags = documentTokens.filter((x) => x.token?.tokenType === LiteralTokenType.Color);
const colorTags = documentTokens.filter((x) => x.token?.type === LiteralTokenType.Color);
const colorRules = new ValueEqualsSet<TextMateRule>();

// Build the new rules for this file
Expand Down
2 changes: 1 addition & 1 deletion src/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
" ",
"@",
"-",
"("
"(",
);

/**
Expand Down Expand Up @@ -88,7 +88,7 @@
const characters = Object.keys(NavigationData.gameObjects["characters"]);

if (prefix === "renpy.music." || prefix === "renpy.audio.") {
prefix = prefix.replace("renpy.", "").trim();

Check warning on line 91 in src/completion.ts

View workflow job for this annotation

GitHub Actions / Lint

Assignment to function parameter 'prefix'
const list = NavigationData.renpyAutoComplete.filter((item) => {
if (typeof item.label === "string") {
item.label.startsWith(prefix);
Expand Down
2 changes: 1 addition & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class Configuration {
this.excludeCompiledFilesConfig();
}
}
})
}),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function injectCustomTextmateTokens(rules: ValueEqualsSet<TextMateRule>)
},
(reason) => {
logMessage(LogLevel.Error, "Failed to update the tokenColorCustomizations config! : " + reason);
}
},
);
}
}
4 changes: 2 additions & 2 deletions src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function refreshDiagnostics(doc: TextDocument, diagnosticCollection: Diag
const diagnostic = new Diagnostic(
range,
`Inconsistent spacing detected (${indention} given, expected a multiple of ${firstIndentation}). Indentation must consist only of spaces in Ren'Py scripts. Each indentation level must consist of the same number of spaces. (4 spaces is strongly recommended.)`,
severity
severity,
);
diagnostics.push(diagnostic);
}
Expand Down Expand Up @@ -175,7 +175,7 @@ export function subscribeToDocumentChanges(context: ExtensionContext, diagnostic
if (editor) {
refreshDiagnostics(editor.document, diagnostics);
}
})
}),
);

context.subscriptions.push(workspace.onDidChangeTextDocument((e) => refreshDiagnostics(e.document, diagnostics)));
Expand Down
46 changes: 28 additions & 18 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import { referencesProvider } from "./references";
import { registerDebugDecorator, unregisterDebugDecorator } from "./tokenizer/debug-decorator";
import { Tokenizer } from "./tokenizer/tokenizer";
import { signatureProvider } from "./signature";
import { intializeLoggingSystems, logMessage, logToast, updateStatusBar } from "./logger";
import { initializeLoggingSystems, logMessage, logToast, updateStatusBar } from "./logger";
import { Configuration } from "./configuration";
import { RenpyAdapterDescriptorFactory, RenpyConfigurationProvider } from "./debugger";
import { RenpyTaskProvider } from "./taskprovider";
import { RenpyTaskProvider } from "./task-provider";

export async function activate(context: ExtensionContext): Promise<void> {
intializeLoggingSystems(context);
initializeLoggingSystems(context);
updateStatusBar("$(sync~spin) Loading Ren'Py extension...");

Configuration.initialize(context);
Expand Down Expand Up @@ -64,13 +64,18 @@ export async function activate(context: ExtensionContext): Promise<void> {

if (!NavigationData.isImporting) {
updateStatusBar("$(sync~spin) Initializing Ren'Py static data...");
const uri = Uri.file(document.fileName);
const filename = stripWorkspaceFromFile(uri.path);
NavigationData.clearScannedDataForFile(filename);
NavigationData.scanDocumentForClasses(filename, document);
updateStatusBar(getStatusBarText());
try {
const uri = Uri.file(document.fileName);
const filename = stripWorkspaceFromFile(uri.path);
NavigationData.clearScannedDataForFile(filename);
NavigationData.scanDocumentForClasses(filename, document);
updateStatusBar(getStatusBarText());
} catch (error) {
updateStatusBar("Failed to load Ren'Py static data...");
logMessage(LogLevel.Error, error as string);
}
}
})
}),
);

// custom command - refresh data
Expand Down Expand Up @@ -161,7 +166,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
request: "launch",
program: rpyPath,
},
{ noDebug: true }
{ noDebug: true },
);

//call renpy
Expand Down Expand Up @@ -201,8 +206,13 @@ export async function activate(context: ExtensionContext): Promise<void> {

// Detect file system change to the navigation.json file and trigger a refresh
updateStatusBar("$(sync~spin) Initializing Ren'Py static data...");
await NavigationData.init(context.extensionPath);
updateStatusBar(getStatusBarText());
try {
await NavigationData.init(context.extensionPath);
updateStatusBar(getStatusBarText());
} catch (error) {
updateStatusBar("Failed to load Ren'Py static data...");
logMessage(LogLevel.Error, error as string);
}

try {
fs.watch(getNavigationJsonFilepath(), async (event, filename) => {
Expand Down Expand Up @@ -270,8 +280,8 @@ export async function activate(context: ExtensionContext): Promise<void> {
];
},
},
DebugConfigurationProviderTriggerKind.Dynamic
)
DebugConfigurationProviderTriggerKind.Dynamic,
),
);

const taskProvider = new RenpyTaskProvider();
Expand Down Expand Up @@ -324,9 +334,9 @@ function RunWorkspaceFolder(): boolean {
if (isValidExecutable(rpyPath)) {
const renpyPath = cleanUpPath(Uri.file(rpyPath).path);
const cwd = renpyPath.substring(0, renpyPath.lastIndexOf("/"));
const workfolder = getWorkspaceFolder();
const args: string[] = [`${workfolder}`, "run"];
if (workfolder.endsWith("/game")) {
const workFolder = getWorkspaceFolder();
const args: string[] = [`${workFolder}`, "run"];
if (workFolder.endsWith("/game")) {
try {
updateStatusBar("$(sync~spin) Running Ren'Py...");
const result = cp.spawnSync(rpyPath, args, {
Expand All @@ -351,7 +361,7 @@ function RunWorkspaceFolder(): boolean {
}
return false;
} else {
logMessage(LogLevel.Warning, "config for rennpy does not exist");
logMessage(LogLevel.Warning, "config for renpy does not exist");
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const statusBar = window.createStatusBarItem(StatusBarAlignment.Right, 100);

let extensionMode: ExtensionMode = null!;

export function intializeLoggingSystems(context: ExtensionContext) {
export function initializeLoggingSystems(context: ExtensionContext) {
extensionMode = context.extensionMode;

context.subscriptions.push(outputChannel);
Expand Down
3 changes: 2 additions & 1 deletion src/navigation-data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { commands, CompletionItem, CompletionItemKind, CompletionItemTag, LogLevel, MarkdownString, Position, SnippetString, TextDocument, window, workspace } from "vscode";
import { getDefinitionFromFile } from "./hover";
import { DataType, getBaseTypeFromDefine, getNamedParameter, getPyDocsFromTextDocumentAtLine, Navigation, splitParameters, stripQuotes } from "./navigation";
Expand Down Expand Up @@ -198,7 +199,7 @@
for (const key in NavigationData.data.location) {
const type = NavigationData.data.location[key];
if (type[keyword]) {
const data = type[keyword];

Check warning on line 202 in src/navigation-data.ts

View workflow job for this annotation

GitHub Actions / Lint

'data' is already declared in the upper scope on line 9 column 8
if (data instanceof Navigation) {
//!data.length
locations.push(data);
Expand Down Expand Up @@ -272,7 +273,7 @@
}

static getNavigationDumpEntry(keyword: string): Navigation | undefined {
const data = NavigationData.getNavigationDumpEntries(keyword);

Check warning on line 276 in src/navigation-data.ts

View workflow job for this annotation

GitHub Actions / Lint

'data' is already declared in the upper scope on line 9 column 8
if (data) {
return data[0];
}
Expand Down Expand Up @@ -573,7 +574,7 @@
}

if (line2.startsWith("@property")) {
const matches = document

Check warning on line 577 in src/navigation-data.ts

View workflow job for this annotation

GitHub Actions / Lint

'matches' is already declared in the upper scope on line 554 column 23
.lineAt(index + 1)
.text.trim()
.match(rxDef);
Expand Down Expand Up @@ -615,7 +616,7 @@
}
let finished = false;
while (!finished && index < document.lineCount) {
let line = document.lineAt(index).text.replace(/[\n\r]/g, "");

Check warning on line 619 in src/navigation-data.ts

View workflow job for this annotation

GitHub Actions / Lint

'line' is already declared in the upper scope on line 608 column 19
if (line.length > 0 && line.length - line.trimStart().length <= spacing) {
finished = true;
break;
Expand Down Expand Up @@ -649,11 +650,11 @@
*/

if (typeof array[0] === "string" && (array[0] === "obsolete" || array[0] === "transitions")) {
source = array[0];

Check warning on line 653 in src/navigation-data.ts

View workflow job for this annotation

GitHub Actions / Lint

Assignment to function parameter 'source'
} else if (typeof array[4] === "string" && array[4] === "Action") {
source = array[4].toLowerCase();

Check warning on line 655 in src/navigation-data.ts

View workflow job for this annotation

GitHub Actions / Lint

Assignment to function parameter 'source'
} else if (source === "equivalent") {
source = array[0];

Check warning on line 657 in src/navigation-data.ts

View workflow job for this annotation

GitHub Actions / Lint

Assignment to function parameter 'source'
}

return new Navigation(
Expand All @@ -663,7 +664,7 @@
0, //location
array[5], //documentation
array[2], //args
array[4] //type
array[4], //type
);
}

Expand Down Expand Up @@ -695,7 +696,7 @@
const key = extractFilenameWithoutExtension(filename);
if (key) {
const path = stripWorkspaceFromFile(cleanUpPath(file.path));
const displayable = new Displayable(key, "image", "", path, -1);

Check warning on line 699 in src/navigation-data.ts

View workflow job for this annotation

GitHub Actions / Lint

'displayable' is already declared in the upper scope on line 694 column 23
NavigationData.data.location["displayable"][key] = displayable;
}
}
Expand Down Expand Up @@ -740,7 +741,7 @@
if (filename.startsWith("game/audio/")) {
const pythonName = NavigationData.getPythonName(filename);
if (pythonName) {
const key = "audio." + extractFilenameWithoutExtension(filename);

Check warning on line 744 in src/navigation-data.ts

View workflow job for this annotation

GitHub Actions / Lint

'key' is already declared in the upper scope on line 736 column 23
if (key && !NavigationData.gameObjects["audio"][key]) {
NavigationData.gameObjects["audio"][key] = key;
}
Expand Down
2 changes: 1 addition & 1 deletion src/semantics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const semanticTokensProvider = languages.registerDocumentSemanticTokensPr
});
},
},
legend
legend,
);

export function getSemanticTokens(document: TextDocument): SemanticTokens {
Expand Down
2 changes: 1 addition & 1 deletion src/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const signatureProvider = languages.registerSignatureHelpProvider(
},
"(",
",",
"="
"=",
);

/**
Expand Down
File renamed without changes.
Loading
Loading