Skip to content

Adding syntax highlighting #1041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions language-configuration.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
{
"autoClosingPairs": [
["<", ">"],
["\"", "\""]
"comments": {
"lineComment": "//",
},
"autoClosingPairs": [
[
"<",
">"
],
"surroundingPairs": [
["<", ">"],
["\"", "\""]
[
"\"",
"\""
]
],
"surroundingPairs": [
[
"<",
">"
],
[
"\"",
"\""
]
]
}
64 changes: 62 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"description": "Gauge support for VScode.",
"author": "ThoughtWorks",
"license": "MIT",
"version": "0.1.6",
"version": "0.1.7",
"publisher": "getgauge",
"engines": {
"vscode": "^1.71.0"
Expand Down Expand Up @@ -288,6 +288,66 @@
"Ignore"
],
"description": "Gauge recommended settings are shown/ignored based on the given value."
},
"gauge.semanticTokenColors.argument": {
"type": "string",
"default": "#ae81ff",
"description": "Color for arguments."
},
"gauge.semanticTokenColors.stepMarker": {
"type": "string",
"default": "#ffffff",
"description": "Color for the step marker '*'"
},
"gauge.semanticTokenColors.step": {
"type": "string",
"default": "#a6e22e",
"description": "Color for step text."
},
"gauge.semanticTokenColors.table": {
"type": "string",
"default": "#ae81ff",
"description": "Color for table rows (cell data)."
},
"gauge.semanticTokenColors.tableHeaderSeparator": {
"type": "string",
"default": "#8349f0",
"description": "Color for table separator dashes."
},
"gauge.semanticTokenColors.tableBorder": {
"type": "string",
"default": "#8349f0",
"description": "Color for table table borders."
},
"gauge.semanticTokenColors.tagKeyword": {
"type": "string",
"default": "#ff4689",
"description": "Color for tag keywords."
},
"gauge.semanticTokenColors.tagValue": {
"type": "string",
"default": "#fc88b2",
"description": "Color for tag values."
},
"gauge.semanticTokenColors.specification": {
"type": "string",
"default": "#66d9ef",
"description": "Color for specification headers."
},
"gauge.semanticTokenColors.scenario": {
"type": "string",
"default": "#66d9ef",
"description": "Color for scenario headers."
},
"gauge.semanticTokenColors.comment": {
"type": "string",
"default": "#cccccc",
"description": "Color for comments."
},
"gauge.semanticTokenColors.disabledStep": {
"type": "string",
"default": "#228549",
"description": "Color for disabled steps."
}
}
},
Expand Down Expand Up @@ -486,4 +546,4 @@
"vscode-languageclient": "~8.1.0",
"xmlbuilder": "^15.1.1"
}
}
}
159 changes: 107 additions & 52 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,112 @@
'use strict';

import { debug, ExtensionContext, languages, window, workspace } from 'vscode';
import { GenerateStubCommandProvider } from './annotator/generateStub';
import { CLI } from './cli';
import { ConfigProvider } from './config/configProvider';
import { ReferenceProvider } from './gaugeReference';
import { GaugeState } from './gaugeState';
import { GaugeWorkspace } from './gaugeWorkspace';
import { ProjectInitializer } from './init/projectInit';
import { ProjectFactory } from './project/projectFactory';
import { hasActiveGaugeDocument } from './util';
import { showInstallGaugeNotification, showWelcomeNotification } from './welcomeNotifications';
import { GaugeClients as GaugeProjectClientMap } from './gaugeClients';

const MINIMUM_SUPPORTED_GAUGE_VERSION = '0.9.6';

const clientsMap: GaugeProjectClientMap = new GaugeProjectClientMap();

export async function activate(context: ExtensionContext) {
let cli = CLI.instance();
if (!cli) {
return;
}
let folders = workspace.workspaceFolders;
context.subscriptions.push(new ProjectInitializer(cli));
let hasGaugeProject = folders && folders.some((f) => ProjectFactory.isGaugeProject(f.uri.fsPath));
if (!hasActiveGaugeDocument(window.activeTextEditor) && !hasGaugeProject) return;
if (!cli.isGaugeInstalled() || !cli.isGaugeVersionGreaterOrEqual(MINIMUM_SUPPORTED_GAUGE_VERSION)) {
return showInstallGaugeNotification();
'use strict';

import { debug, ExtensionContext, languages, window, workspace, ConfigurationTarget } from 'vscode';
import { GenerateStubCommandProvider } from './annotator/generateStub';
import { CLI } from './cli';
import { ConfigProvider } from './config/configProvider';
import { ReferenceProvider } from './gaugeReference';
import { GaugeState } from './gaugeState';
import { GaugeWorkspace } from './gaugeWorkspace';
import { ProjectInitializer } from './init/projectInit';
import { ProjectFactory } from './project/projectFactory';
import { hasActiveGaugeDocument } from './util';
import { showInstallGaugeNotification, showWelcomeNotification } from './welcomeNotifications';
import { GaugeClients as GaugeProjectClientMap } from './gaugeClients';
import { GaugeSemanticTokensProvider, legend } from './semanticTokensProvider';

const MINIMUM_SUPPORTED_GAUGE_VERSION = '0.9.6';

const clientsMap: GaugeProjectClientMap = new GaugeProjectClientMap();

// This function reads Gauge-specific semantic token colors from the configuration
// and then updates the editor.semanticTokenColorCustomizations setting.
function updateGaugeSemanticTokenColors() {
// Read Gauge settings from the gauge configuration section.
const gaugeConfig = workspace.getConfiguration("gauge.semanticTokenColors");
const colors = {
argument: gaugeConfig.get("argument"),
stepMarker: gaugeConfig.get("stepMarker"),
step: gaugeConfig.get("step"),
table: gaugeConfig.get("table"),
tableHeaderSeparator: gaugeConfig.get("tableHeaderSeparator"),
tableBorder: gaugeConfig.get("tableBorder"),
tagKeyword: gaugeConfig.get("tagKeyword"),
tagValue: gaugeConfig.get("tagValue"),
specification: gaugeConfig.get("specification"),
scenario: gaugeConfig.get("scenario"),
comment: gaugeConfig.get("comment"),
disabledStep: gaugeConfig.get("disabledStep")
};

// Build a new set of semantic token color rules.
const semanticTokenRules = {
"argument": { "foreground": colors.argument },
"stepMarker": { "foreground": colors.stepMarker },
"step": { "foreground": colors.step },
"table": { "foreground": colors.table },
"tableHeaderSeparator": { "foreground": colors.tableHeaderSeparator },
"tableBorder": { "foreground": colors.tableBorder },
"tagKeyword": { "foreground": colors.tagKeyword },
"tagValue": { "foreground": colors.tagValue },
"specification": { "foreground": colors.specification },
"scenario": { "foreground": colors.scenario },
"comment": { "foreground": colors.comment },
"disabledStep": { "foreground": colors.disabledStep }
};

// Get the current global editor configuration.
const editorConfig = workspace.getConfiguration("editor");

// Update the semantic token color customizations.
editorConfig.update("semanticTokenColorCustomizations", { rules: semanticTokenRules }, ConfigurationTarget.Global);
}
showWelcomeNotification(context);
languages.setLanguageConfiguration('gauge', { wordPattern: /^(?:[*])([^*].*)$/g });
let gaugeWorkspace = new GaugeWorkspace(new GaugeState(context), cli, clientsMap);

context.subscriptions.push(
gaugeWorkspace,
new ReferenceProvider(clientsMap),
new GenerateStubCommandProvider(clientsMap),
new ConfigProvider(context),
debug.registerDebugConfigurationProvider('gauge',
{
resolveDebugConfiguration: () => {
throw Error("Starting with the Gauge debug configuration is not supported. Please use the 'Gauge' commands instead.");

export async function activate(context: ExtensionContext) {
let cli = CLI.instance();
if (!cli) {
return;
}
let folders = workspace.workspaceFolders;
context.subscriptions.push(new ProjectInitializer(cli));
let hasGaugeProject = folders && folders.some((f) => ProjectFactory.isGaugeProject(f.uri.fsPath));
if (!hasActiveGaugeDocument(window.activeTextEditor) && !hasGaugeProject) return;
if (!cli.isGaugeInstalled() || !cli.isGaugeVersionGreaterOrEqual(MINIMUM_SUPPORTED_GAUGE_VERSION)) {
return showInstallGaugeNotification();
}
showWelcomeNotification(context);
languages.setLanguageConfiguration('gauge', { wordPattern: /^(?:[*])([^*].*)$/g });
let gaugeWorkspace = new GaugeWorkspace(new GaugeState(context), cli, clientsMap);
updateGaugeSemanticTokenColors();

context.subscriptions.push(
gaugeWorkspace,
new ReferenceProvider(clientsMap),
new GenerateStubCommandProvider(clientsMap),
new ConfigProvider(context),
debug.registerDebugConfigurationProvider('gauge',
{
resolveDebugConfiguration: () => {
throw Error("Starting with the Gauge debug configuration is not supported. Please use the 'Gauge' commands instead.");
}
}),
languages.registerDocumentSemanticTokensProvider(
{ language: 'gauge' },
new GaugeSemanticTokensProvider(),
legend
),
workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration("gauge.semanticTokenColors")) {
updateGaugeSemanticTokenColors();
}
})
);
}
);
}

export function deactivate(): Thenable<void> {
const promises: Thenable<void>[] = [];
export function deactivate(): Thenable<void> {
const promises: Thenable<void>[] = [];

for (const {client} of clientsMap.values()) {
promises.push(client.stop());
}
return Promise.all(promises).then(() => undefined);
}
for (const { client } of clientsMap.values()) {
promises.push(client.stop());
}
return Promise.all(promises).then(() => undefined);
}
Loading
Loading