Skip to content

Commit

Permalink
Merge pull request #414 from renpy/various-bug-fixes
Browse files Browse the repository at this point in the history
Various bug fixes and improvements
  • Loading branch information
duckdoom4 authored Jul 10, 2024
2 parents 6aaa03c + 7b9b08d commit 8d04712
Show file tree
Hide file tree
Showing 32 changed files with 1,187 additions and 723 deletions.
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 @@ export const completionProvider = languages.registerCompletionItemProvider(
" ",
"@",
"-",
"("
"(",
);

/**
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 @@ -663,7 +664,7 @@ export class NavigationData {
0, //location
array[5], //documentation
array[2], //args
array[4] //type
array[4], //type
);
}

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

0 comments on commit 8d04712

Please sign in to comment.