Skip to content

Commit d338f1a

Browse files
authored
Develop (#19)
1 parent d90c891 commit d338f1a

File tree

27 files changed

+833
-1443
lines changed

27 files changed

+833
-1443
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.3
8+
9+
Refactored state manager, added rebounce, updated transpiler & validator, added restart command
10+
711
### 0.3.2
812

913
Added new keywords of the Bitloops Language (DomainEvent, IntegrationEvent, DomainService)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ No known issues.
3333

3434
## What's New
3535

36-
### 0.3.2
36+
### 0.3.3
3737

38-
Added new keywords of the Bitloops Language (DomainEvent, IntegrationEvent, DomainService)
38+
Refactored state manager, added rebounce, updated transpiler & validator, added restart command
3939

4040
---
4141

client/src/extension.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* ------------------------------------------------------------------------------------------ */
55

66
import * as path from 'path';
7-
import { workspace, ExtensionContext } from 'vscode';
7+
import { workspace, ExtensionContext, commands } from 'vscode';
88

99
import {
1010
LanguageClient,
@@ -40,14 +40,25 @@ export function activate(context: ExtensionContext) {
4040
documentSelector: [{ scheme: 'file', language: 'bitloops' }],
4141
synchronize: {
4242
// Notify the server about file changes to '.clientrc files contained in the workspace
43-
fileEvents: workspace.createFileSystemWatcher('**/.clientrc'),
43+
fileEvents: workspace.createFileSystemWatcher('**/*.{bl,clientrc}'),
4444
},
4545
};
4646

4747
// Create the language client and start the client.
4848
client = new LanguageClient('Bitloops LSP', 'Bitloops LSP', serverOptions, clientOptions);
4949
// console.log(client);
5050

51+
// Register Restart command
52+
let disposable = commands.registerCommand('bitloops.restartLSP', async () => {
53+
if (client) {
54+
if (client.needsStop()) {
55+
await client.stop();
56+
}
57+
client.start();
58+
}
59+
});
60+
context.subscriptions.push(disposable);
61+
5162
// Start the client. This will also launch the server
5263
client.start();
5364
}

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"icon": "assets/images/bitloops-language-logo-256x256.png",
1111
"license": "MIT",
12-
"version": "0.3.2",
12+
"version": "0.3.3",
1313
"scripts": {
1414
"vs:package": "vsce package",
1515
"vs:publish": "vsce publish",
@@ -78,6 +78,12 @@
7878
"scopeName": "source.bitloops",
7979
"path": "./syntaxes/bitloops.tmLanguage.json"
8080
}
81+
],
82+
"commands": [
83+
{
84+
"command": "bitloops.restartLSP",
85+
"title": "Bitloops: Restart LSP Server"
86+
}
8187
]
8288
},
8389
"devDependencies": {

server/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
### File structure
2+
3+
File structure that incorporates the idea of having separate files for different request handlers and better organization:
4+
5+
```
6+
server/
7+
src/
8+
index.ts # Entry point for the server
9+
lsp/
10+
bitloopsServer.ts # Bitloops language server implementation
11+
handlers/
12+
completionHandler.ts # Completion request handler
13+
hoverHandler.ts # Hover request handler
14+
// Other request handlers...
15+
models/
16+
// Language-specific models, interfaces, or types
17+
utils/
18+
// Utility functions or helper modules
19+
package.json # Package dependencies and scripts
20+
tsconfig.json # TypeScript compiler configuration for server
21+
```
22+
23+
Explanation of the structure:
24+
25+
- src/index.ts: The entry point for the server application.
26+
- src/lsp/server.ts: This file contains the implementation of the Bitloops language server. It can handle various LSP features and delegate specific request handling to separate handler modules.
27+
- src/lsp/client.ts: This file contains the implementation of the LSP Client, used to push results generated by the server, to the user's interface.
28+
- src/lsp/handlers/: This directory now contains individual files for different request handlers. For example, completionHandler.ts handles completion requests, hoverHandler.ts handles hover requests, and so on. You can create additional files for other request handlers as needed.
29+
- src/lsp/models/: This directory still holds language-specific models, interfaces, or types that are used by the LSP server and request handlers.
30+
- src/utils/: This directory remains for utility functions or helper modules.

server/package.json

Lines changed: 4 additions & 2 deletions
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.3.2",
4+
"version": "0.3.3",
55
"publisher": "Bitloops",
66
"license": "MIT",
77
"engines": {
@@ -10,13 +10,15 @@
1010
"type": "module",
1111
"scripts": {},
1212
"dependencies": {
13-
"@bitloops/bl-transpiler": "^0.2.0",
13+
"@bitloops/bl-transpiler": "^0.6.0",
14+
"debounce": "^1.2.1",
1415
"fs": "^0.0.1-security",
1516
"path": "^0.12.7",
1617
"vscode-languageserver": "^7.0.0",
1718
"vscode-languageserver-textdocument": "^1.0.4"
1819
},
1920
"devDependencies": {
21+
"@types/debounce": "^1.2.1",
2022
"prettier": "^2.7.1",
2123
"rimraf": "^3.0.2",
2224
"typescript": "^4.8.4"

server/src/analyzer.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.

server/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { LspConnection } from './lsp-connection.js';
1+
import { LspConnection } from './lsp/connection.js';
22

33
new LspConnection().registerLspEvents().listen();

server/src/lsp-client.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

server/src/lsp/client.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as lsp from 'vscode-languageserver';
2+
3+
export interface ILspClient {
4+
publishDiagnostics(args: lsp.PublishDiagnosticsParams): void;
5+
emptyFileDiagnostics(fileUri: string): void;
6+
showLoadingProgress(message: string): void;
7+
hideLoadingProgress(): void;
8+
9+
showErrorMessage(message: string): void;
10+
showWarningMessage(message: string): void;
11+
}
12+
13+
export class LspClientImpl implements ILspClient {
14+
constructor(protected connection: lsp.Connection) {}
15+
showLoadingProgress(message: string): void {
16+
throw new Error('Method not implemented.');
17+
}
18+
hideLoadingProgress(): void {
19+
throw new Error('Method not implemented.');
20+
}
21+
22+
publishDiagnostics(params: lsp.PublishDiagnosticsParams): void {
23+
this.connection.sendDiagnostics(params);
24+
}
25+
26+
emptyFileDiagnostics(fileUri: string): void {
27+
this.connection.sendDiagnostics({ uri: fileUri, diagnostics: [] });
28+
}
29+
showErrorMessage(message: string): void {
30+
this.connection.window.showErrorMessage(message);
31+
}
32+
33+
showWarningMessage(message: string): void {
34+
this.connection.window.showWarningMessage(message);
35+
}
36+
}

server/src/lsp-connection.ts renamed to server/src/lsp/connection.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import {
66
} from 'vscode-languageserver/node.js';
77

88
import { TextDocument } from 'vscode-languageserver-textdocument';
9-
import { LspClientImpl } from './lsp-client.js';
9+
import debounce from 'debounce';
10+
import { LspClientImpl } from './client.js';
1011
import { BitloopsServer } from './server.js';
1112

13+
const DEBOUNCE_INTERVAL = 500;
14+
1215
export class LspConnection {
1316
private connection: _Connection;
1417
private server: BitloopsServer;
@@ -28,9 +31,14 @@ export class LspConnection {
2831
this.connection.onInitialized(server.onInitialized.bind(server));
2932

3033
this.documents.onDidClose(server.onDidClose.bind(server));
31-
this.documents.onDidChangeContent(server.onDidChangeContent.bind(server));
34+
this.documents.onDidChangeContent(
35+
debounce(server.onDidChangeContent.bind(server), DEBOUNCE_INTERVAL),
36+
);
3237
this.connection.onCompletion(server.completion.bind(server, this.documents));
3338
this.connection.onCompletionResolve(server.completionResolve.bind(server));
39+
40+
this.connection.onDidChangeWatchedFiles(server.onDidChangeWatchedFiles.bind(server));
41+
3442
return this;
3543
}
3644

server/src/completion.ts renamed to server/src/lsp/handlers/completion-handler/completion.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
TextDocumentPositionParams,
77
TextDocuments,
88
} from 'vscode-languageserver/node.js';
9-
import { documentation } from './information/documentation.js';
10-
import { details } from './information/details.js';
11-
import { allKeywords, components, keywords } from './types/keywords.js';
9+
import { documentation } from '../../../information/documentation.js';
10+
import { details } from '../../../information/details.js';
11+
import { allKeywords } from '../../models/keywords.js';
1212
import { TextDocument } from 'vscode-languageserver-textdocument';
1313

1414
//this would come from package

0 commit comments

Comments
 (0)