Skip to content

Commit

Permalink
fix: Resolved issue with syntax highlighting caused by the delayed re…
Browse files Browse the repository at this point in the history
…processing of files during editing
  • Loading branch information
adam-coster committed Jul 25, 2023
1 parent 5fa207c commit 6211250
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
"stitch.editing.reprocessOnTypeDelay": {
"title": "Reprocess on type delay",
"type": "number",
"default": 250,
"default": 50,
"description": "The delay in milliseconds to wait after a keypress before reprocessing the document. This is used to avoid reprocessing the document while the user is typing. Increase this value if the editor is feeling sluggish. Note that certain actions and typed characters will trigger a reprocess no matter what this is set to."
},
"stitch.run.defaultConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode/src/extension.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class StitchConfig {
return this.config.get<string>('run.defaultConfig') || null;
}
get reprocessOnTypeDelay(): number {
return this.config.get<number>('editing.reprocessOnTypeDelay') || 250;
return this.config.get<number>('editing.reprocessOnTypeDelay') || 50;
}
}

Expand Down
14 changes: 11 additions & 3 deletions packages/vscode/src/extension.provider.mts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class StitchProvider
vscode.DefinitionProvider,
vscode.ReferenceProvider
{
readonly semanticHighlightProvider = new GameMakerSemanticTokenProvider(this);
readonly signatureHelpStatus = vscode.window.createStatusBarItem(
config.functionSignatureStatusAlignment,
config.functionSignatureStatusAlignment === vscode.StatusBarAlignment.Left
Expand Down Expand Up @@ -405,7 +406,9 @@ export class StitchProvider
clearTimeout(this.debouncingOnChange.get(doc.uri.fsPath));
this.debouncingOnChange.set(
doc.uri.fsPath,
setTimeout(() => this.onChangeDoc(doc), config.reprocessOnTypeDelay),
setTimeout(() => {
this.onChangeDoc(doc);
}, config.reprocessOnTypeDelay),
);
return;
}
Expand All @@ -420,7 +423,12 @@ export class StitchProvider
// Add the processing promise to a map so
// that other functionality can wait for it
// to complete.
const updateWait = StitchProvider.provider.updateFile(doc);
const updateWait = StitchProvider.provider.updateFile(doc).finally(() => {
// Semantic highlighting is normally updated by VSCode
// upon change. But since we're delaying processing of the
// file, we need to manually trigger a refresh.
this.semanticHighlightProvider.refresh();
});
this.processingFiles.set(doc.uri.fsPath, updateWait);
await updateWait;
this.processingFiles.delete(doc.uri.fsPath);
Expand Down Expand Up @@ -570,7 +578,7 @@ export class StitchProvider
);
this.provider.getProject(uri)?.openInIde();
}),
new GameMakerSemanticTokenProvider(this.provider).register(),
this.provider.semanticHighlightProvider.register(),
this.provider.signatureHelpStatus,
vscode.window.onDidChangeTextEditorSelection((e) => {
// This includes events from the output window, so skip those
Expand Down
24 changes: 22 additions & 2 deletions packages/vscode/src/extension.semanticTokens.mts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ export class GameMakerSemanticTokenProvider
{
constructor(readonly provider: StitchProvider) {}

private _onDidChangeSemanticTokens: vscode.EventEmitter<void> =
new vscode.EventEmitter();
readonly onDidChangeSemanticTokens = this._onDidChangeSemanticTokens.event;

refresh() {
this._onDidChangeSemanticTokens.fire();
}

provideDocumentSemanticTokens(
document: vscode.TextDocument,
): vscode.SemanticTokens | undefined {
Expand All @@ -57,6 +65,14 @@ export class GameMakerSemanticTokenProvider
{ type: SemanticTokenType; mods: Set<SemanticTokenModifier> }
>();
for (const ref of file.refs) {
if (
!ref.start ||
isNaN(ref.start.line) ||
!ref.end ||
isNaN(ref.end.line)
) {
continue;
}
// Get the location as a vscode range
const signifier = ref.item;

Expand Down Expand Up @@ -103,7 +119,11 @@ export class GameMakerSemanticTokenProvider
} catch (err) {
warn(err);
warn('PUSH ERROR');
console.dir({ range, tokenType, tokenModifiers });
console.dir({
range,
tokenType,
tokenModifiers,
});
}
}
const tokens = tokensBuilder.build();
Expand Down Expand Up @@ -146,7 +166,7 @@ function inferSemanticToken(ref: Reference): SemanticTokenType {
if (signifier.parameter) {
return 'parameter';
}
if (signifier.instance) {
if (signifier.instance && !!signifier.def) {
return 'property';
}
return 'variable';
Expand Down

0 comments on commit 6211250

Please sign in to comment.