Skip to content

Commit

Permalink
[vscode] Report syntax errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
pfusik committed Jan 26, 2023
1 parent b5fd6e7 commit 733a8a5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
1 change: 1 addition & 0 deletions editors/vscode/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/node_modules
/out
/package-lock.json
/src/parser.js
4 changes: 2 additions & 2 deletions editors/vscode/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ VERSION = 2.1.0
run: ci-$(VERSION).vsix
'$(LOCALAPPDATA)\Programs\Microsoft VS Code\bin\code' --extensionDevelopmentPath=$(abspath .)

ci-$(VERSION).vsix: package.json ci-logo.png ci-file.svg language-configuration.json tsconfig.json syntaxes/ci.tmLanguage.json out/parser.js src/extension.ts
ci-$(VERSION).vsix: package.json ci-logo.png ci-file.svg language-configuration.json tsconfig.json syntaxes/ci.tmLanguage.json src/extension.ts src/parser.js
$(APPDATA)/npm/vsce package

out/parser.js: ../../Lexer.ci ../../AST.ci ../../Parser.ci
src/parser.js: ../../Lexer.ci ../../AST.ci ../../Parser.ci
cito -o $@ $^
48 changes: 32 additions & 16 deletions editors/vscode/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
import * as vscode from "vscode";
import { CiParser, CiProgram, CiSystem } from "./parser.js";

export function activate(context: vscode.ExtensionContext) {
// vscode.window.showInformationMessage("Hello, world!");
const diagnosticCollection = vscode.languages.createDiagnosticCollection("ci");
if (vscode.window.activeTextEditor) {
updateDiagnostics(vscode.window.activeTextEditor.document, diagnosticCollection);
class VsCodeParser extends CiParser
{
private system = CiSystem.new();
diagnostics: vscode.Diagnostic[] = [];

protected reportError(message: string) : void
{
this.diagnostics.push(new vscode.Diagnostic(new vscode.Range(this.line - 1, 0, this.line, 0), message));
}

updateDiagnostics(document: vscode.TextDocument, diagnosticCollection: vscode.DiagnosticCollection): void
{
if (document.languageId != "ci")
return;
this.diagnostics.length = 0;
this.program = new CiProgram();
this.program.parent = this.system;
this.program.system = this.system;
const input = new TextEncoder().encode(document.getText());
this.parse(document.fileName, input, input.length);
diagnosticCollection.set(document.uri, this.diagnostics);
}
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(editor => {
if (editor) {
updateDiagnostics(editor.document, diagnosticCollection);
}
}));
}

function updateDiagnostics(document: vscode.TextDocument, diagnosticCollection: vscode.DiagnosticCollection): void {
if (document.languageId != "ci")
return;
const diagnostics = [];
diagnostics.push(new vscode.Diagnostic(new vscode.Range(0, 0, 1, 0), "hello"));
diagnosticCollection.set(document.uri, diagnostics);
export function activate(context: vscode.ExtensionContext): void {
const parser = new VsCodeParser();
const diagnosticCollection = vscode.languages.createDiagnosticCollection("ci");
if (vscode.window.activeTextEditor)
parser.updateDiagnostics(vscode.window.activeTextEditor.document, diagnosticCollection);
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(editor => {
if (editor)
parser.updateDiagnostics(editor.document, diagnosticCollection);
}));
context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(e => parser.updateDiagnostics(e.document, diagnosticCollection)));
}
15 changes: 8 additions & 7 deletions editors/vscode/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"files": [
"src/extension.ts",
"src/parser.js"
],
"compilerOptions": {
"target": "es2021",
"module": "commonjs",
"rootDir" : "src",
"outDir": "out",
"strict": true
},
"exclude": [
"node_modules"
]
"allowJs": true,
"strict": true,
"outDir": "out"
}
}

0 comments on commit 733a8a5

Please sign in to comment.