Skip to content

Commit bfff728

Browse files
Adding syntax highlighting (#1041)
* Adding code & default config syntax highlighting. Signed-off-by: Jens Johansson <[email protected]> * Adding code & default config syntax highlighting. Signed-off-by: Jens Johansson <[email protected]> * Adding code & default config syntax highlighting. Signed-off-by: Jens Johansson <[email protected]> * Adding code & default config syntax highlighting. Signed-off-by: Jens Johansson <[email protected]> --------- Signed-off-by: Jens Johansson <[email protected]>
1 parent ce908fa commit bfff728

File tree

4 files changed

+375
-60
lines changed

4 files changed

+375
-60
lines changed

language-configuration.json

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
{
2-
"autoClosingPairs": [
3-
["<", ">"],
4-
["\"", "\""]
2+
"comments": {
3+
"lineComment": "//",
4+
},
5+
"autoClosingPairs": [
6+
[
7+
"<",
8+
">"
59
],
6-
"surroundingPairs": [
7-
["<", ">"],
8-
["\"", "\""]
10+
[
11+
"\"",
12+
"\""
913
]
14+
],
15+
"surroundingPairs": [
16+
[
17+
"<",
18+
">"
19+
],
20+
[
21+
"\"",
22+
"\""
23+
]
24+
]
1025
}

package.json

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"description": "Gauge support for VScode.",
99
"author": "ThoughtWorks",
1010
"license": "MIT",
11-
"version": "0.1.6",
11+
"version": "0.1.7",
1212
"publisher": "getgauge",
1313
"engines": {
1414
"vscode": "^1.71.0"
@@ -288,6 +288,66 @@
288288
"Ignore"
289289
],
290290
"description": "Gauge recommended settings are shown/ignored based on the given value."
291+
},
292+
"gauge.semanticTokenColors.argument": {
293+
"type": "string",
294+
"default": "#ae81ff",
295+
"description": "Color for arguments."
296+
},
297+
"gauge.semanticTokenColors.stepMarker": {
298+
"type": "string",
299+
"default": "#ffffff",
300+
"description": "Color for the step marker '*'"
301+
},
302+
"gauge.semanticTokenColors.step": {
303+
"type": "string",
304+
"default": "#a6e22e",
305+
"description": "Color for step text."
306+
},
307+
"gauge.semanticTokenColors.table": {
308+
"type": "string",
309+
"default": "#ae81ff",
310+
"description": "Color for table rows (cell data)."
311+
},
312+
"gauge.semanticTokenColors.tableHeaderSeparator": {
313+
"type": "string",
314+
"default": "#8349f0",
315+
"description": "Color for table separator dashes."
316+
},
317+
"gauge.semanticTokenColors.tableBorder": {
318+
"type": "string",
319+
"default": "#8349f0",
320+
"description": "Color for table table borders."
321+
},
322+
"gauge.semanticTokenColors.tagKeyword": {
323+
"type": "string",
324+
"default": "#ff4689",
325+
"description": "Color for tag keywords."
326+
},
327+
"gauge.semanticTokenColors.tagValue": {
328+
"type": "string",
329+
"default": "#fc88b2",
330+
"description": "Color for tag values."
331+
},
332+
"gauge.semanticTokenColors.specification": {
333+
"type": "string",
334+
"default": "#66d9ef",
335+
"description": "Color for specification/concept headers."
336+
},
337+
"gauge.semanticTokenColors.scenario": {
338+
"type": "string",
339+
"default": "#66d9ef",
340+
"description": "Color for scenario headers."
341+
},
342+
"gauge.semanticTokenColors.comment": {
343+
"type": "string",
344+
"default": "#cccccc",
345+
"description": "Color for comments."
346+
},
347+
"gauge.semanticTokenColors.disabledStep": {
348+
"type": "string",
349+
"default": "#228549",
350+
"description": "Color for disabled steps."
291351
}
292352
}
293353
},
@@ -486,4 +546,4 @@
486546
"vscode-languageclient": "~8.1.0",
487547
"xmlbuilder": "^15.1.1"
488548
}
489-
}
549+
}

src/extension.ts

Lines changed: 107 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,112 @@
1-
'use strict';
2-
3-
import { debug, ExtensionContext, languages, window, workspace } from 'vscode';
4-
import { GenerateStubCommandProvider } from './annotator/generateStub';
5-
import { CLI } from './cli';
6-
import { ConfigProvider } from './config/configProvider';
7-
import { ReferenceProvider } from './gaugeReference';
8-
import { GaugeState } from './gaugeState';
9-
import { GaugeWorkspace } from './gaugeWorkspace';
10-
import { ProjectInitializer } from './init/projectInit';
11-
import { ProjectFactory } from './project/projectFactory';
12-
import { hasActiveGaugeDocument } from './util';
13-
import { showInstallGaugeNotification, showWelcomeNotification } from './welcomeNotifications';
14-
import { GaugeClients as GaugeProjectClientMap } from './gaugeClients';
15-
16-
const MINIMUM_SUPPORTED_GAUGE_VERSION = '0.9.6';
17-
18-
const clientsMap: GaugeProjectClientMap = new GaugeProjectClientMap();
19-
20-
export async function activate(context: ExtensionContext) {
21-
let cli = CLI.instance();
22-
if (!cli) {
23-
return;
24-
}
25-
let folders = workspace.workspaceFolders;
26-
context.subscriptions.push(new ProjectInitializer(cli));
27-
let hasGaugeProject = folders && folders.some((f) => ProjectFactory.isGaugeProject(f.uri.fsPath));
28-
if (!hasActiveGaugeDocument(window.activeTextEditor) && !hasGaugeProject) return;
29-
if (!cli.isGaugeInstalled() || !cli.isGaugeVersionGreaterOrEqual(MINIMUM_SUPPORTED_GAUGE_VERSION)) {
30-
return showInstallGaugeNotification();
1+
'use strict';
2+
3+
import { debug, ExtensionContext, languages, window, workspace, ConfigurationTarget } from 'vscode';
4+
import { GenerateStubCommandProvider } from './annotator/generateStub';
5+
import { CLI } from './cli';
6+
import { ConfigProvider } from './config/configProvider';
7+
import { ReferenceProvider } from './gaugeReference';
8+
import { GaugeState } from './gaugeState';
9+
import { GaugeWorkspace } from './gaugeWorkspace';
10+
import { ProjectInitializer } from './init/projectInit';
11+
import { ProjectFactory } from './project/projectFactory';
12+
import { hasActiveGaugeDocument } from './util';
13+
import { showInstallGaugeNotification, showWelcomeNotification } from './welcomeNotifications';
14+
import { GaugeClients as GaugeProjectClientMap } from './gaugeClients';
15+
import { GaugeSemanticTokensProvider, legend } from './semanticTokensProvider';
16+
17+
const MINIMUM_SUPPORTED_GAUGE_VERSION = '0.9.6';
18+
19+
const clientsMap: GaugeProjectClientMap = new GaugeProjectClientMap();
20+
21+
// This function reads Gauge-specific semantic token colors from the configuration
22+
// and then updates the editor.semanticTokenColorCustomizations setting.
23+
function updateGaugeSemanticTokenColors() {
24+
// Read Gauge settings from the gauge configuration section.
25+
const gaugeConfig = workspace.getConfiguration("gauge.semanticTokenColors");
26+
const colors = {
27+
argument: gaugeConfig.get("argument"),
28+
stepMarker: gaugeConfig.get("stepMarker"),
29+
step: gaugeConfig.get("step"),
30+
table: gaugeConfig.get("table"),
31+
tableHeaderSeparator: gaugeConfig.get("tableHeaderSeparator"),
32+
tableBorder: gaugeConfig.get("tableBorder"),
33+
tagKeyword: gaugeConfig.get("tagKeyword"),
34+
tagValue: gaugeConfig.get("tagValue"),
35+
specification: gaugeConfig.get("specification"),
36+
scenario: gaugeConfig.get("scenario"),
37+
comment: gaugeConfig.get("comment"),
38+
disabledStep: gaugeConfig.get("disabledStep")
39+
};
40+
41+
// Build a new set of semantic token color rules.
42+
const semanticTokenRules = {
43+
"argument": { "foreground": colors.argument },
44+
"stepMarker": { "foreground": colors.stepMarker },
45+
"step": { "foreground": colors.step },
46+
"table": { "foreground": colors.table },
47+
"tableHeaderSeparator": { "foreground": colors.tableHeaderSeparator },
48+
"tableBorder": { "foreground": colors.tableBorder },
49+
"tagKeyword": { "foreground": colors.tagKeyword },
50+
"tagValue": { "foreground": colors.tagValue },
51+
"specification": { "foreground": colors.specification },
52+
"scenario": { "foreground": colors.scenario },
53+
"comment": { "foreground": colors.comment },
54+
"disabledStep": { "foreground": colors.disabledStep }
55+
};
56+
57+
// Get the current global editor configuration.
58+
const editorConfig = workspace.getConfiguration("editor");
59+
60+
// Update the semantic token color customizations.
61+
editorConfig.update("semanticTokenColorCustomizations", { rules: semanticTokenRules }, ConfigurationTarget.Global);
3162
}
32-
showWelcomeNotification(context);
33-
languages.setLanguageConfiguration('gauge', { wordPattern: /^(?:[*])([^*].*)$/g });
34-
let gaugeWorkspace = new GaugeWorkspace(new GaugeState(context), cli, clientsMap);
35-
36-
context.subscriptions.push(
37-
gaugeWorkspace,
38-
new ReferenceProvider(clientsMap),
39-
new GenerateStubCommandProvider(clientsMap),
40-
new ConfigProvider(context),
41-
debug.registerDebugConfigurationProvider('gauge',
42-
{
43-
resolveDebugConfiguration: () => {
44-
throw Error("Starting with the Gauge debug configuration is not supported. Please use the 'Gauge' commands instead.");
63+
64+
export async function activate(context: ExtensionContext) {
65+
let cli = CLI.instance();
66+
if (!cli) {
67+
return;
68+
}
69+
let folders = workspace.workspaceFolders;
70+
context.subscriptions.push(new ProjectInitializer(cli));
71+
let hasGaugeProject = folders && folders.some((f) => ProjectFactory.isGaugeProject(f.uri.fsPath));
72+
if (!hasActiveGaugeDocument(window.activeTextEditor) && !hasGaugeProject) return;
73+
if (!cli.isGaugeInstalled() || !cli.isGaugeVersionGreaterOrEqual(MINIMUM_SUPPORTED_GAUGE_VERSION)) {
74+
return showInstallGaugeNotification();
75+
}
76+
showWelcomeNotification(context);
77+
languages.setLanguageConfiguration('gauge', { wordPattern: /^(?:[*])([^*].*)$/g });
78+
let gaugeWorkspace = new GaugeWorkspace(new GaugeState(context), cli, clientsMap);
79+
updateGaugeSemanticTokenColors();
80+
81+
context.subscriptions.push(
82+
gaugeWorkspace,
83+
new ReferenceProvider(clientsMap),
84+
new GenerateStubCommandProvider(clientsMap),
85+
new ConfigProvider(context),
86+
debug.registerDebugConfigurationProvider('gauge',
87+
{
88+
resolveDebugConfiguration: () => {
89+
throw Error("Starting with the Gauge debug configuration is not supported. Please use the 'Gauge' commands instead.");
90+
}
91+
}),
92+
languages.registerDocumentSemanticTokensProvider(
93+
{ language: 'gauge' },
94+
new GaugeSemanticTokensProvider(),
95+
legend
96+
),
97+
workspace.onDidChangeConfiguration((e) => {
98+
if (e.affectsConfiguration("gauge.semanticTokenColors")) {
99+
updateGaugeSemanticTokenColors();
45100
}
46101
})
47-
);
48-
}
102+
);
103+
}
49104

50-
export function deactivate(): Thenable<void> {
51-
const promises: Thenable<void>[] = [];
105+
export function deactivate(): Thenable<void> {
106+
const promises: Thenable<void>[] = [];
52107

53-
for (const {client} of clientsMap.values()) {
54-
promises.push(client.stop());
55-
}
56-
return Promise.all(promises).then(() => undefined);
57-
}
108+
for (const { client } of clientsMap.values()) {
109+
promises.push(client.stop());
110+
}
111+
return Promise.all(promises).then(() => undefined);
112+
}

0 commit comments

Comments
 (0)