Skip to content

Commit 11fd8a6

Browse files
committed
Add validation command
1 parent b4dccca commit 11fd8a6

File tree

9 files changed

+101
-79
lines changed

9 files changed

+101
-79
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## 0.4.3 (-, 2022)
22
- Definition file dependency validation
3-
- Validation commands
3+
- Validation command
44

55
## 0.4.2 (July 6, 2022)
66
- Fix a bug if an undefined symbol crashes the validator

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ This extension contributes the following settings:
247247
* `macro.lint`: Lint settings and rule configuration
248248
* `macro.sequence.base`: Sequences start number for refactoring
249249
* `macro.sequence.increment`: Sequences increment for refactoring
250-
* `macro.codelens.enable`: Enables or disables the CodeLens function. **Deprecated**: Please use `editor.codeLens` instead.
251250
* `macro.validate.enable`: Enables or disables the validation
252251
* `macro.validate.workspace`: Enables or disables the workspace validation
252+
* `macro.validate.onBuild`: Enables or disables the workspace validation when building the project
253253

254254
Build settings:
255255
* `macro.build.compiler`: Selection of the macro compiler

client/src/common/commands.ts

+7-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as vscode from 'vscode';
77
import * as path from 'path';
88
import CompositeDisposable from './compositeDisposable';
9-
import { WorkspaceFolder } from 'vscode-languageclient';
9+
import { pickFolder } from '../extension';
1010

1111
const COMPILER = ['MCOMPI', 'MCOMP0', 'MCOMP30I', 'MCOMP15', 'MCOMP15I'];
1212

@@ -119,23 +119,6 @@ function setExportPath () {
119119
});
120120
}
121121

122-
function pickFolder(cb:(workspace:vscode.WorkspaceFolder) => void) {
123-
const folders = vscode.workspace.workspaceFolders;
124-
if (folders.length === 1) {
125-
cb(folders[0]);
126-
return;
127-
}
128-
vscode.window.showWorkspaceFolderPick({placeHolder:'', ignoreFocusOut:true}).then(selected => {
129-
if (selected) {
130-
cb(selected);
131-
}
132-
});
133-
if (folders.length === 1) {
134-
cb(folders[0]);
135-
return;
136-
}
137-
}
138-
139122
class ProjectService {
140123

141124
private getRelativePath(p:string, workspacePath:string, includeWsFolder:boolean = false) : string {
@@ -169,9 +152,15 @@ class ProjectService {
169152
}
170153

171154
public async build() {
155+
172156
pickFolder(async workspace => {
157+
173158
const config = vscode.workspace.getConfiguration('macro', workspace);
174159

160+
if (config.validate.onBuild) {
161+
vscode.commands.executeCommand('macro.action.validate', workspace.uri.toString());
162+
}
163+
175164
const makeFile = config.build.makeFile;
176165
const exportPath= config.project.exportPath;
177166
const compiler = config.build.compiler;

client/src/extension.ts

+58-36
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
import * as path from 'path';
2-
import { workspace as Workspace, ExtensionContext, workspace, commands, window as Window,
3-
Location,
4-
} from 'vscode';
5-
6-
import {
7-
LanguageClient, LanguageClientOptions,
8-
ServerOptions, TransportKind, RevealOutputChannelOn,
9-
ExecuteCommandSignature, WorkspaceFolder
10-
} from 'vscode-languageclient/node';
11-
12-
2+
import * as vscode from 'vscode';
3+
import * as lc from 'vscode-languageclient/node';
134
import * as ls from 'vscode-languageserver-protocol';
145

156
import registerCommands from './common/commands';
167

178
import CompositeDisposable from './common/compositeDisposable';
189

19-
let client: LanguageClient;
10+
let client: lc.LanguageClient;
2011
let disposables = new CompositeDisposable();
2112

2213
interface ConfigurationSettings {
@@ -33,7 +24,7 @@ interface ConfigurationSettings {
3324
}
3425
lint?: Object;
3526
keywords: Object[],
36-
workspaceFolder?: WorkspaceFolder | undefined;
27+
workspaceFolder?: lc.WorkspaceFolder | undefined;
3728
callFunctions?: string[];
3829
}
3930

@@ -42,79 +33,90 @@ interface CodeLensReferenceArgument {
4233
locations: ls.Location[]
4334
}
4435

45-
export function activate(context: ExtensionContext) {
36+
export function activate(context: vscode.ExtensionContext) {
4637

4738
// The server is implemented in node
4839
let serverModule = context.asAbsolutePath(
4940
path.join('server', 'out', 'server.js')
5041
);
5142

5243
let debugOptions = { execArgv: ['--nolazy', '--inspect=6011'], cwd: process.cwd() };
53-
let serverOptions: ServerOptions = {
54-
run: { module: serverModule, transport: TransportKind.ipc, options: { cwd: process.cwd() } },
44+
let serverOptions: lc.ServerOptions = {
45+
run: { module: serverModule, transport: lc.TransportKind.ipc, options: { cwd: process.cwd() } },
5546
debug: {
5647
module: serverModule,
57-
transport: TransportKind.ipc,
48+
transport: lc.TransportKind.ipc,
5849
options: debugOptions
5950
}
6051
};
6152

62-
let clientOptions: LanguageClientOptions = {
53+
let clientOptions: lc.LanguageClientOptions = {
6354
documentSelector: [{ language: 'macro', scheme: 'file' }],
64-
initializationOptions: workspace.getConfiguration('macro'),
55+
initializationOptions: vscode.workspace.getConfiguration('macro'),
6556
synchronize: {
66-
fileEvents: workspace.createFileSystemWatcher('**/*.{[sS][rR][cC],[dD][eE][fF],[lL][nN][kK]}')
57+
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.{[sS][rR][cC],[dD][eE][fF],[lL][nN][kK]}')
6758
},
6859
diagnosticCollectionName: 'macro',
6960
progressOnInitialization: true,
70-
revealOutputChannelOn: RevealOutputChannelOn.Never,
61+
revealOutputChannelOn: lc.RevealOutputChannelOn.Never,
7162
middleware: {
72-
73-
executeCommand: async (command:string, args:any[], next:ExecuteCommandSignature) => {
63+
64+
executeCommand: async (command:string, args:any[], next:lc.ExecuteCommandSignature) => {
7465
if (command === 'macro.codelens.references') {
7566
const arg:CodeLensReferenceArgument = args[0];
7667

7768

7869
const position = client.protocol2CodeConverter.asPosition(arg.position);
79-
const locations:Location[] = [];
70+
const locations:vscode.Location[] = [];
8071
for (const location of arg.locations){
8172
locations.push(client.protocol2CodeConverter.asLocation(location));
8273
}
8374

84-
if (Window.activeTextEditor) {
85-
commands.executeCommand('editor.action.showReferences', Window.activeTextEditor.document.uri, position, locations);
75+
if (vscode.window.activeTextEditor) {
76+
vscode.commands.executeCommand('editor.action.showReferences', vscode.window.activeTextEditor.document.uri, position, locations);
8677
}
8778
}
8879
else if (command === 'macro.action.refactorsequeces' || command === 'macro.action.addsequeces') {
8980
function validate(input:string): string | null {
9081
return Number.isInteger(Number(input)) ? null : 'Integer expected';
9182
}
9283

93-
const config = workspace.getConfiguration('macro');
84+
const config = vscode.workspace.getConfiguration('macro');
9485
let start = undefined;
9586
if (command === 'macro.action.refactorsequeces') {
96-
start = await Window.showInputBox({
87+
start = await vscode.window.showInputBox({
9788
prompt: 'Start sequence number',
9889
value: config.sequence.base,
9990
validateInput: validate
10091
});
10192
}
10293

103-
const increment = await Window.showInputBox({
94+
const increment = await vscode.window.showInputBox({
10495
prompt: 'Sequence number increment',
10596
value: config.sequence.increment,
10697
validateInput: validate
10798
});
10899

109-
if (Window.activeTextEditor) {
100+
if (vscode.window.activeTextEditor) {
110101
if (command === 'macro.action.addsequeces' && increment) {
111-
return next(command, [Window.activeTextEditor.document.uri.toString(), Window.activeTextEditor.selection.start, increment]);
102+
return next(command, [vscode.window.activeTextEditor.document.uri.toString(), vscode.window.activeTextEditor.selection.start, increment]);
112103
}
113104
else if (command === 'macro.action.refactorsequeces' && start && increment) {
114-
return next(command, [Window.activeTextEditor.document.uri.toString(), Window.activeTextEditor.selection.start, start, increment]);
105+
return next(command, [vscode.window.activeTextEditor.document.uri.toString(), vscode.window.activeTextEditor.selection.start, start, increment]);
115106
}
116107
}
117108
}
109+
else if (command === 'macro.action.validate') {
110+
const workspaceUri = args[0];
111+
if (workspaceUri) {
112+
return next(command, [workspaceUri]);
113+
}
114+
else {
115+
pickFolder(workspace => {
116+
return next(command, [workspace.uri.toString()]);
117+
});
118+
}
119+
}
118120
},
119121
workspace : {
120122
configuration: async (params, _token, _next): Promise<any[]> => {
@@ -128,8 +130,8 @@ export function activate(context: ExtensionContext) {
128130
continue;
129131
}
130132
const resource = client.protocol2CodeConverter.asUri(item.scopeUri);
131-
const workspaceFolder = Workspace.getWorkspaceFolder(resource);
132-
const config = workspace.getConfiguration('macro', workspaceFolder);
133+
const workspaceFolder = vscode.workspace.getWorkspaceFolder(resource);
134+
const config = vscode.workspace.getConfiguration('macro', workspaceFolder);
133135
const settings: ConfigurationSettings = {
134136
codelens: config.get('codelens'),
135137
lint:config.get('lint', {}),
@@ -153,9 +155,8 @@ export function activate(context: ExtensionContext) {
153155
} as any
154156
};
155157

156-
157158
// Create the language client and start the client.
158-
client = new LanguageClient(
159+
client = new lc.LanguageClient(
159160
'macroLanguageServer',
160161
'Macro Language Server',
161162
serverOptions,
@@ -173,3 +174,24 @@ export function deactivate(): Thenable<void> | undefined {
173174
}
174175
return client.stop();
175176
}
177+
178+
export function pickFolder(cb:(workspace: vscode.WorkspaceFolder) => void) {
179+
const folders = vscode.workspace.workspaceFolders;
180+
if (!folders) {
181+
return;
182+
}
183+
184+
if (folders.length === 1) {
185+
cb(folders[0]);
186+
return;
187+
}
188+
vscode.window.showWorkspaceFolderPick({placeHolder:'', ignoreFocusOut:true}).then(selected => {
189+
if (selected) {
190+
cb(selected);
191+
}
192+
});
193+
if (folders.length === 1) {
194+
cb(folders[0]);
195+
return;
196+
}
197+
}

i18n/chs/package.i18n.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
"macro.setControlType": "选择NC系统类型",
88
"macro.action.addsequeces": "添加缺失的顺序号",
99
"macro.action.refactorsequeces": "重排顺序号",
10+
"macro.action.validate" : "Validate Workspace",
1011
"macro.callFunctions.description": "子程序调用",
1112
"macro.lint.description": "Lint设置",
1213
"macro.sequence.base.description": "顺序起始号",
1314
"macro.sequence.increment.description": "顺序号增量",
14-
"macro.codelens.enable.description": "CodeLens使能",
1515
"macro.validate.enable.description": "代码校验",
1616
"macro.validate.workspace.description": "环境校验",
17+
"macro.validate.onBuild.description": "Enables or disables the workspace validation when building the project",
1718
"macro.build.compiler.description": "选择宏编译器",
1819
"macro.build.controlType.description": "选择NC系统类型",
1920
"macro.build.compilerParams.description": "附加其他编译参数 -NR -L1 -L2 -L3 -PR",

i18n/deu/package.i18n.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
"macro.setControlType": "Steuerungstyp auswählen",
88
"macro.action.addsequeces": "Fehlende Sequenznummern hinzufügen",
99
"macro.action.refactorsequeces": "Sequenznummern neu ordnen",
10+
"macro.action.validate" : "Überprüfung des gesamten Arbeitsbereichs",
1011
"macro.callFunctions.description": "Benutzerdefinierte Funktionen zum Aufrufen von Unterprogrammen",
1112
"macro.lint.description": "Lint Einstellungen",
1213
"macro.sequence.base.description": "Startnummer der Sequenzen für das Refactoring",
1314
"macro.sequence.increment.description": "Inkrement der Sequenzen für Refactoring",
14-
"macro.codelens.enable.description": " Aktiviert oder deaktiviert die CodeLens Funktion",
1515
"macro.validate.enable.description": "Aktiviert oder deaktiviert alle Überprüfungen",
1616
"macro.validate.workspace.description": "Aktiviert oder deaktiviert die Überprüfung des gesamten Arbeitsbereichs",
17+
"macro.validate.onBuild.description": "Aktiviert oder deaktiviert die Überprüfung des gesamten Arbeitsbereichs beim Erstellen des Projekts",
1718
"macro.build.compiler.description": "Auswahl des Macro-Compilers",
1819
"macro.build.controlType.description": "Auswahl des Steuerungstyps",
1920
"macro.build.compilerParams.description": "Zusätzliche Compilerparameter: -NR, -L1, -L2, -L3, -PR",
@@ -23,4 +24,4 @@
2324
"macro.project.sourcePath.description": "Der Pfad zu dem Verzeichnis wo die Source-Dateien (.src) liegen",
2425
"macro.project.buildPath.description": "Der Pfad zu dem Verzeichnis wo der Compiler die erstellten Dateien ablegt",
2526
"macro.project.linkPath.description": "Der Pfad zu dem Verzeichnis wo die Link-Dateien (.lnk) liegen. Im gleichen Verzeichnis befindet sich auch die Bibliothek .mex"
26-
}
27+
}

package.json

+8-10
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@
105105
"category": "Macro"
106106
},
107107
{
108-
"command": "macro.validate.workspace",
109-
"title": "%macro.validate.workspace%",
108+
"command": "macro.action.validate",
109+
"title": "%macro.action.validate%",
110110
"category": "Macro"
111111
}
112112
],
@@ -419,14 +419,6 @@
419419
"default": 10,
420420
"description": "%macro.sequence.increment.description%"
421421
},
422-
"macro.codelens.enable": {
423-
"scope": "resource",
424-
"type": "boolean",
425-
"default": true,
426-
"description": "%macro.codelens.enable.description%",
427-
"markdownDeprecationMessage": "**Deprecated**: Please use `#editor.codeLens#` instead.",
428-
"deprecationMessage": "Deprecated: Please use editor.codeLens instead."
429-
},
430422
"macro.validate.enable": {
431423
"scope": "resource",
432424
"type": "boolean",
@@ -439,6 +431,12 @@
439431
"default": true,
440432
"description": "%macro.validate.workspace.description%"
441433
},
434+
"macro.validate.onBuild": {
435+
"scope": "resource",
436+
"type": "boolean",
437+
"default": false,
438+
"description": "%macro.validate.onBuild.description%"
439+
},
442440
"macro.build.compiler": {
443441
"type": "string",
444442
"scope": "resource",

package.nls.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
"macro.setControlType": "Select Control Type",
88
"macro.action.addsequeces": "Add missing sequence numbers",
99
"macro.action.refactorsequeces": "Reorganize sequence numbers",
10-
10+
"macro.action.validate" : "Validate Workspace",
1111
"macro.callFunctions.description": "Custom call functions",
1212
"macro.lint.description": "Lint settings",
1313
"macro.sequence.base.description": "Sequences start number for refactoring",
1414
"macro.sequence.increment.description": "Sequences increment for refactoring",
15-
"macro.codelens.enable.description": "Enables or disables the CodeLens function",
1615
"macro.validate.enable.description": "Enables or disables the validation",
1716
"macro.validate.workspace.description": "Enables or disables the workspace validation",
17+
"macro.validate.onBuild.description": "Enables or disables the workspace validation when building the project",
1818
"macro.build.compiler.description": "Selection of the macro compiler",
1919
"macro.build.controlType.description": "Selection of the control type",
2020
"macro.build.compilerParams.description": "Additional compiler parameters: -NR, -L1, -L2, -L3, -PR",

0 commit comments

Comments
 (0)