Skip to content

Commit 82af239

Browse files
committed
Needs fix with tsconfig options
1 parent a59c166 commit 82af239

File tree

6 files changed

+84
-32
lines changed

6 files changed

+84
-32
lines changed

.vscode/launch.json

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,39 @@
33
// Hover to view descriptions of existing attributes.
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
{
6-
"version": "0.2.0",
7-
"configurations": [
8-
{
9-
"name": "Extension",
10-
"type": "extensionHost",
11-
"request": "launch",
12-
"args": [
13-
"--extensionDevelopmentPath=${workspaceFolder}"
14-
]
15-
}
16-
]
17-
}
6+
"version": "0.2.0",
7+
"configurations": [
8+
{
9+
"name": "Extension",
10+
"type": "extensionHost",
11+
"request": "launch",
12+
"args": ["--extensionDevelopmentPath=${workspaceFolder}"]
13+
},
14+
{
15+
"type": "extensionHost",
16+
"request": "launch",
17+
"name": "Launch Client",
18+
"runtimeExecutable": "${execPath}",
19+
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
20+
"outFiles": ["${workspaceRoot}/client/out/**/*.js"],
21+
"preLaunchTask": {
22+
"type": "npm",
23+
"script": "watch"
24+
}
25+
},
26+
{
27+
"type": "node",
28+
"request": "attach",
29+
"name": "Attach to Server",
30+
"port": 6009,
31+
"restart": true,
32+
"outFiles": ["${workspaceRoot}/server/out/**/*.js"]
33+
}
34+
],
35+
"compounds": [
36+
{
37+
"name": "Client + Server",
38+
"configurations": ["Launch Client", "Attach to Server"]
39+
}
40+
]
41+
}

client/src/extension.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
import * as path from 'path';
77
import { workspace, ExtensionContext } from 'vscode';
88

9-
import {
10-
LanguageClient,
11-
LanguageClientOptions,
12-
ServerOptions,
13-
TransportKind,
14-
} from 'vscode-languageclient/node';
9+
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node';
1510

1611
let client: LanguageClient;
1712

@@ -46,7 +41,7 @@ export function activate(context: ExtensionContext) {
4641

4742
// Create the language client and start the client.
4843
client = new LanguageClient('Bitloops LSP', 'Bitloops LSP', serverOptions, clientOptions);
49-
console.log(client);
44+
// console.log(client);
5045

5146
// Start the client. This will also launch the server
5247
client.start();

server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "bitloops-lsp-server",
3+
"type": "module",
34
"description": "BitLoops Language Server",
45
"version": "1.0.0",
56
"publisher": "Bitloops",

server/src/linter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Connection } from 'vscode-languageserver';
22
import { getDocumentSettings } from './setings';
33
import { TextDocument } from 'vscode-languageserver-textdocument';
44
import { IAnalyzer, RegexAnalyzer } from './analyzer';
5+
import { AntlrAnalyzer } from './parser/index';
56

67
const analyzer: IAnalyzer = new RegexAnalyzer();
78
let problems = 0;
@@ -14,6 +15,8 @@ export async function lint(
1415
// In this simple example we get the settings for every validate run.
1516
const settings = await getDocumentSettings(textDocument.uri, hasConfigurationCapability, connection);
1617

18+
const analyzerAntlr: IAnalyzer = new AntlrAnalyzer();
19+
console.debug('visited analyzer');
1720
// const pattern = /\b[A-Z]{2,}\b/g;
1821
let diagnostics = analyzer.analyze(textDocument);
1922
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });

server/src/parser/index.ts

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,49 @@
11
import antlr4 from 'antlr4';
22
import Lexer from 'antlr4/Lexer.js';
33
import { TextDocument } from 'vscode-languageserver-textdocument';
4+
import Recognizer from 'antlr4/Recognizer';
5+
import Token from 'antlr4/Token';
46
import { IAnalyzer } from '../analyzer.js';
57
import BitloopsVisitor from './BitloopsVisitor/BitloopsVisitor.js';
68
import BitloopsLexer from './grammar/BitloopsLexer.js';
79
import BitloopsParser from './grammar/BitloopsParser.js';
810

9-
export class BitloopsIntermediateASTParser implements IAnalyzer {
11+
// import { ErrorListener } from 'antlr4/error';
12+
class VerboseListener {
13+
syntaxError = (
14+
_recognizer: Recognizer,
15+
_offendingSymbol: Token,
16+
line: number,
17+
column: number,
18+
_msg: string,
19+
_e: any
20+
) => {
21+
// const stack: any = recognizer.getTokenErrorDisplay(offendingSymbol);
22+
// console.log("rule stack: "+stack);
23+
console.log(`line: ${line}:${column}, offendingSymbol : ${_offendingSymbol.text}, msg: ${_msg}`);
24+
};
25+
}
26+
27+
export class AntlrAnalyzer implements IAnalyzer {
1028
analyze(document: TextDocument): any[] {
11-
const textFile = document.getText();
12-
const chars = new antlr4.InputStream(textFile);
13-
const lexer: Lexer = new BitloopsLexer(chars) as any;
14-
const tokens = new antlr4.CommonTokenStream(lexer);
15-
const parser = new BitloopsParser(tokens);
16-
const tree = parser.program();
17-
const bitloopsVisitor = new BitloopsVisitor();
18-
const result = bitloopsVisitor.visit(tree);
19-
console.log('result', result);
20-
return [];
29+
try {
30+
const textFile = document.getText();
31+
32+
const chars = new antlr4.InputStream(textFile);
33+
const lexer: Lexer = new BitloopsLexer(chars) as any;
34+
const tokens = new antlr4.CommonTokenStream(lexer);
35+
const parser = new BitloopsParser(tokens) as any;
36+
37+
parser.removeErrorListeners();
38+
parser.addErrorListener(new VerboseListener() as any);
39+
const tree = parser.program();
40+
const bitloopsVisitor = new BitloopsVisitor();
41+
const result = bitloopsVisitor.visit(tree).catch((e) => {});
42+
console.log('result', result);
43+
return [];
44+
} catch (e) {
45+
console.log('error', e);
46+
return [];
47+
}
2148
}
2249
}

server/tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
"compilerOptions": {
33
"target": "es2020",
44
"lib": ["es2020"],
5-
"module": "commonjs",
5+
"module": "ES2020",
66
"moduleResolution": "node",
77
"sourceMap": true,
88
"strict": true,
99
"outDir": "out",
1010
"rootDir": "src",
11-
"noImplicitAny": false
11+
"noImplicitAny": false,
12+
"checkJs": false,
13+
"allowJs": true
1214
},
1315
"include": ["src"],
1416
"exclude": ["node_modules", ".vscode-test"]

0 commit comments

Comments
 (0)