Skip to content

Commit 1f1eadd

Browse files
authored
Merge pull request #43 from SSlinky/dev
Add Formatting Capability
2 parents d92337a + 48e36ab commit 1f1eadd

35 files changed

+2715
-489
lines changed

.editorconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
# Template from: https://github.com/DecimalTurn/VBA-on-GitHub
3+
4+
# top-most EditorConfig file
5+
root = true
6+
7+
# Properties for VBA, VB6 and twinBASIC file extensions
8+
[*.{bas,cls,frm,vba,doccls,ctl,dsr,twin,tbform}]
9+
indent_style = space
10+
indent_size = 4
11+
end_of_line = crlf
12+
# Avoid line too long error (https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/line-too-long):
13+
max_line_length = 1023
14+
insert_final_newline = true
15+
trim_trailing_whitespace = true
16+
17+
# The character set property isn't widely supported, but you can still add it. It just won't do anything if unsupported by your editor.
18+
# Reference: https://github.com/editorconfig/editorconfig/issues/209#issuecomment-445241830
19+
# Eg.:
20+
# charset = windows-1252
21+
# charset = us-ascii

.github/workflows/node.js.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ jobs:
3030
# For some reason, antlr4ng writes to a different location on the VM
3131
# than it does locally, preventing compile. Command added to move the generated files.
3232
- run: npm run textMate
33-
- name: npm run antlr4ng
34-
run: npm run antlr4ng && npm run antlr4ngPre && mv ./server/src/antlr/out/server/src/antlr/* ./server/src/antlr/out
33+
- name: npm run antlr
34+
run: |
35+
npm run antlr4ng
36+
npm run antlr4ngPre
37+
npm run antlr4ngFmt
38+
mv ./server/src/antlr/out/server/src/antlr/* ./server/src/antlr/out
3539
- run: npm run compile
3640
- run: xvfb-run -a npm test
3741
if: runner.os == 'Linux'

.vscode/launch.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@
5757
"printParseTree": true,
5858
"visualParseTree": true
5959
},
60+
{
61+
"name": "Debug ANTLR4 Fmt grammar",
62+
"type": "antlr-debug",
63+
"request": "launch",
64+
"input": "${file}",
65+
"grammar": "server/src/antlr/vbafmt.g4",
66+
"startRule": "startRule",
67+
"printParseTree": true,
68+
"visualParseTree": true
69+
},
6070
{
6171
"name": "Extension Tests",
6272
"type": "extensionHost",

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Adds VBA language support to VSCode via LSP compliant Language Server.
1010
* Semantic highlighting
1111
* Folding ranges
1212
* Document symbols
13+
* Document formatting\*
14+
15+
\*Currently full document `Shift+Alt+F` formatting only.
1316

1417
## Coming Soon
1518

@@ -18,7 +21,7 @@ Adds VBA language support to VSCode via LSP compliant Language Server.
1821

1922
## Installation
2023

21-
* Through the VBA Marketplace,
24+
* Through the VSCode Marketplace,
2225
* VSCode command palette `ext install notisdataanalytics.vba-lsp`, or;
2326
* Download the [visx](../../releases/latest).
2427

client/src/extension.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ServerOptions,
1313
TransportKind
1414
} from 'vscode-languageclient/node';
15+
import { VscodeLogger } from './logger';
1516

1617
let client: LanguageClient;
1718

@@ -53,8 +54,14 @@ export function activate(context: ExtensionContext) {
5354
clientOptions
5455
);
5556

57+
// Add logging support for messages received from the server.
58+
client.onNotification("window/logMessage", (params) => {
59+
VscodeLogger.logMessage(params);
60+
})
61+
5662
// Start the client. This will also launch the server
5763
client.start();
64+
VscodeLogger.info('VBAPro activated')
5865
}
5966

6067
export function deactivate(): Thenable<void> | undefined {

client/src/logger.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import * as vscode from 'vscode';
2+
3+
enum LogLevel {
4+
error = 1,
5+
warning = 2,
6+
info = 3,
7+
log = 4,
8+
debug = 5
9+
}
10+
11+
export interface LogMessage {
12+
type: number;
13+
message: string;
14+
level: number;
15+
}
16+
17+
export class VscodeLogger {
18+
private static _outputChannel: vscode.OutputChannel;
19+
static get outputChannel(): vscode.OutputChannel {
20+
if (!VscodeLogger._outputChannel) {
21+
VscodeLogger._outputChannel = vscode.window.createOutputChannel('VBAPro Output');
22+
VscodeLogger._outputChannel.show();
23+
}
24+
return VscodeLogger._outputChannel;
25+
}
26+
27+
static info = (msg: string, lvl?: number) => this.log(LogLevel.info, msg, lvl)
28+
static debug = (msg: string, lvl?: number) => this.log(LogLevel.debug, msg, lvl)
29+
30+
static logMessage(params: LogMessage): void {
31+
this.log(params.type, params.message, params.level);
32+
}
33+
34+
private static log(type: LogLevel, msg: string, lvl?: number): void {
35+
const i = '> '.repeat(lvl ?? 0);
36+
const t = `${this.getFormattedTimestamp()}`;
37+
VscodeLogger.outputChannel.appendLine(`${t} [${LogLevel[type]}] ${i}${msg}`);
38+
}
39+
40+
private static getFormattedTimestamp(): string {
41+
const now = new Date();
42+
43+
const year = now.getFullYear();
44+
const month = (now.getMonth() + 1).toString().padStart(2, "0");
45+
const day = now.getDate().toString().padStart(2, "0");
46+
47+
const hours = now.getHours().toString().padStart(2, "0");
48+
const minutes = now.getMinutes().toString().padStart(2, "0");
49+
const seconds = now.getSeconds().toString().padStart(2, "0");
50+
const milliseconds = now.getMilliseconds().toString().padStart(3, "0");
51+
52+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`;
53+
}
54+
}
55+

0 commit comments

Comments
 (0)