Skip to content

Commit 85acb56

Browse files
authored
Merge pull request #11 from bitloops/validate-all-files
added validation after initialization
2 parents beab37e + 5c87dd7 commit 85acb56

File tree

8 files changed

+94
-9
lines changed

8 files changed

+94
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to the "bitloops-language" extension will be documented in t
44

55
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
66

7+
### 0.3.0
8+
9+
Added validation after the initialization of the workspace
10+
711
### 0.2.0
812

913
Added validator for semantic and syntactic errors

client/.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "all",
4+
"singleQuote": true,
5+
"printWidth": 100,
6+
"tabWidth": 2
7+
}

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "bitloops-server-client",
33
"description": "BitLoops Server Client",
44
"license": "MIT",
5-
"version": "0.0.1",
5+
"version": "0.3.0",
66
"publisher": "Bitloops",
77
"engines": {
88
"vscode": "^1.63.0"

client/src/extension.ts

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

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

1116
let client: LanguageClient;
1217

server/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bitloops-lsp-server",
33
"description": "BitLoops Language Server",
4-
"version": "0.2.0",
4+
"version": "0.3.0",
55
"publisher": "Bitloops",
66
"license": "MIT",
77
"engines": {
@@ -11,6 +11,8 @@
1111
"scripts": {},
1212
"dependencies": {
1313
"@bitloops/bl-transpiler": "^0.2.0",
14+
"fs": "^0.0.1-security",
15+
"path": "^0.12.7",
1416
"vscode-languageserver": "^7.0.0",
1517
"vscode-languageserver-textdocument": "^1.0.4"
1618
},

server/src/parser/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class BitloopsAnalyzer implements IAnalyzer {
2626
return this.diagnostics;
2727
}
2828
if (isIntermediateASTValidationErrors(intermediateModel)) {
29-
this.mapValidatorErrorsToLSPDiagnostics(intermediateModel, document);
29+
this.mapValidatorErrorsToLSPDiagnostics(intermediateModel);
3030
return this.diagnostics;
3131
}
3232
return this.diagnostics;
@@ -74,7 +74,10 @@ export class BitloopsAnalyzer implements IAnalyzer {
7474
}
7575
return this.res as TParserInputData;
7676
}
77-
mapParserErrorsToLSPDiagnostics(parserErrors: OriginalParserError, document: TextDocument): void {
77+
private mapParserErrorsToLSPDiagnostics(
78+
parserErrors: OriginalParserError,
79+
document: TextDocument,
80+
): void {
7881
parserErrors.forEach((e) => {
7982
this.diagnostics[e.fileId] = [];
8083
});
@@ -96,10 +99,7 @@ export class BitloopsAnalyzer implements IAnalyzer {
9699
);
97100
}
98101

99-
mapValidatorErrorsToLSPDiagnostics(
100-
validatorErrors: OriginalValidatorError,
101-
document: TextDocument,
102-
): void {
102+
private mapValidatorErrorsToLSPDiagnostics(validatorErrors: OriginalValidatorError): void {
103103
validatorErrors.forEach((e) => {
104104
this.diagnostics[e.metadata.fileId] = [];
105105
});

server/src/server.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
TextDocumentSyncKind,
88
DidChangeConfigurationNotification,
99
Diagnostic,
10+
Connection,
11+
WorkspaceFolder,
1012
} from 'vscode-languageserver/node.js';
1113

1214
import { TextDocument } from 'vscode-languageserver-textdocument';
@@ -15,6 +17,9 @@ import { WorkspaceSettingsManager } from './settings.js';
1517
import { IAnalyzer } from './analyzer.js';
1618
import { ILspClient } from './lsp-client.js';
1719
import { BitloopsAnalyzer } from './parser/index.js';
20+
import * as fs from 'fs';
21+
import * as path from 'path';
22+
1823
// Create a connection for the server, using Node's IPC as a transport.
1924
// Also include all preview / proposed LSP features.
2025

@@ -32,6 +37,7 @@ export class BitloopsServer {
3237
private hasConfigurationCapability = false;
3338
private hasWorkspaceFolderCapability = false;
3439
private hasDiagnosticRelatedInformationCapability = false;
40+
private workspaceFolders: WorkspaceFolder[] = [];
3541

3642
constructor(lspClient: ILspClient, connection: _Connection) {
3743
// Create a simple text document manager.
@@ -50,6 +56,8 @@ export class BitloopsServer {
5056
// }
5157

5258
public onInitialize(params: InitializeParams): InitializeResult {
59+
this.workspaceFolders = params.workspaceFolders;
60+
5361
const capabilities = params.capabilities;
5462
this.hasConfigurationCapability = !!(
5563
capabilities.workspace && !!capabilities.workspace.configuration
@@ -75,6 +83,7 @@ export class BitloopsServer {
7583
},
7684
};
7785
}
86+
7887
return result;
7988
}
8089

@@ -83,6 +92,7 @@ export class BitloopsServer {
8392
// Register for all configuration changes.
8493
this.connection.client.register(DidChangeConfigurationNotification.type, undefined);
8594
}
95+
this.validateWorkspace(this.workspaceFolders);
8696
if (this.hasWorkspaceFolderCapability) {
8797
this.connection.workspace.onDidChangeWorkspaceFolders((_event) => {
8898
this.connection.console.log('Workspace folder change event received.');
@@ -110,4 +120,31 @@ export class BitloopsServer {
110120
this.lspClient.publishDiagnostics({ uri: uri, diagnostics: diagnostic });
111121
}
112122
}
123+
124+
private async validateWorkspace(workspaceFolders: WorkspaceFolder[]) {
125+
for (const workspaceFolder of workspaceFolders) {
126+
const workspaceRoot = path.resolve(workspaceFolder.uri.replace('file://', ''));
127+
const files = fs.readdirSync(workspaceRoot);
128+
await this.validateBitloopsFiles(workspaceRoot);
129+
}
130+
}
131+
132+
private async validateBitloopsFiles(startPath) {
133+
var files = fs.readdirSync(startPath);
134+
for (var i = 0; i < files.length; i++) {
135+
var filename = path.join(startPath, files[i]);
136+
var stat = fs.lstatSync(filename);
137+
if (stat.isDirectory()) {
138+
this.validateBitloopsFiles(filename);
139+
} else if (filename.endsWith('.bl')) {
140+
const textDocument = TextDocument.create(
141+
'file://' + filename,
142+
'bitloops',
143+
1,
144+
fs.readFileSync(filename, 'utf8'),
145+
);
146+
await this.createDiagnostics(textDocument);
147+
}
148+
}
149+
}
113150
}

server/yarn.lock

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ fs.realpath@^1.0.0:
3939
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
4040
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==
4141

42+
fs@^0.0.1-security:
43+
version "0.0.1-security"
44+
resolved "https://registry.yarnpkg.com/fs/-/fs-0.0.1-security.tgz#8a7bd37186b6dddf3813f23858b57ecaaf5e41d4"
45+
integrity sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==
46+
4247
glob@^7.1.3:
4348
version "7.2.3"
4449
resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b"
@@ -64,6 +69,11 @@ inherits@2:
6469
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
6570
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
6671

72+
inherits@2.0.3:
73+
version "2.0.3"
74+
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
75+
integrity sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw==
76+
6777
lodash@^4.17.21:
6878
version "4.17.21"
6979
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
@@ -88,11 +98,24 @@ path-is-absolute@^1.0.0:
8898
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
8999
integrity sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==
90100

101+
path@^0.12.7:
102+
version "0.12.7"
103+
resolved "https://registry.yarnpkg.com/path/-/path-0.12.7.tgz#d4dc2a506c4ce2197eb481ebfcd5b36c0140b10f"
104+
integrity sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q==
105+
dependencies:
106+
process "^0.11.1"
107+
util "^0.10.3"
108+
91109
prettier@^2.7.1:
92110
version "2.7.1"
93111
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64"
94112
integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==
95113

114+
process@^0.11.1:
115+
version "0.11.10"
116+
resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"
117+
integrity sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==
118+
96119
rimraf@^3.0.2:
97120
version "3.0.2"
98121
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a"
@@ -105,6 +128,13 @@ typescript@^4.8.4:
105128
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6"
106129
integrity sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==
107130

131+
util@^0.10.3:
132+
version "0.10.4"
133+
resolved "https://registry.yarnpkg.com/util/-/util-0.10.4.tgz#3aa0125bfe668a4672de58857d3ace27ecb76901"
134+
integrity sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==
135+
dependencies:
136+
inherits "2.0.3"
137+
108138
vscode-jsonrpc@6.0.0:
109139
version "6.0.0"
110140
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-6.0.0.tgz#108bdb09b4400705176b957ceca9e0880e9b6d4e"

0 commit comments

Comments
 (0)