Skip to content

Commit

Permalink
refactor: optimization of activation processing (#724)
Browse files Browse the repository at this point in the history
* refactor: optimization of activation processing

* chore: activation process fine tuning

* fix: add stanbul ignore files in sonar cloud config

* fix: remove async await

---------

Co-authored-by: Alexander Gilin <alexander.gilin@sap.com>
  • Loading branch information
marufrasully and alex-gilin authored Aug 20, 2024
1 parent 583b3cc commit bfcac90
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 38 deletions.
7 changes: 7 additions & 0 deletions .changeset/unlucky-items-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"vscode-ui5-language-assistant": patch
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch
"@ui5-language-assistant/language-server": patch
---

activation process fine tuning
4 changes: 4 additions & 0 deletions packages/language-server/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const defaultConfig = require("../../jest.config");

module.exports = {
...defaultConfig,
coveragePathIgnorePatterns: [
"<rootDir>/src/server.ts",
"<rootDir>/scripts/update-diagnostics-snapshots.js",
],
globals: {
"ts-jest": {
tsconfig: join(__dirname, "tsconfig-test.json"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* istanbul ignore file - dev scripts don't need tests */
const klawSync = require("klaw-sync");
const { forEach, filter, map } = require("lodash");
const { resolve, dirname } = require("path");
Expand Down
1 change: 0 additions & 1 deletion packages/language-server/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* istanbul ignore file */
import { forEach } from "lodash";
import {
createConnection,
Expand Down
4 changes: 4 additions & 0 deletions packages/vscode-ui5-language-assistant/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const defaultConfig = require("../../jest.config");

module.exports = {
...defaultConfig,
coveragePathIgnorePatterns: [
"<rootDir>/scripts/package-vsix.js",
"<rootDir>/src/extension.ts",
],
globals: {
"ts-jest": {
tsconfig: join(__dirname, "tsconfig-test.json"),
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-ui5-language-assistant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"main": "./lib/src/extension",
"activationEvents": [
"onFileSystem:manifest-schema",
"*"
"onLanguage:xml"
],
"contributes": {
"semanticTokenScopes": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* istanbul ignore file */
/**
* Workaround to: https://github.com/microsoft/vscode-vsce/issues/300
* This "sorts of" implements the (broken) `yarn list` with support for workspaces
Expand Down
83 changes: 49 additions & 34 deletions packages/vscode-ui5-language-assistant/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* istanbul ignore file */
import { resolve } from "path";
import { readFileSync } from "fs";
import {
Expand Down Expand Up @@ -55,24 +54,15 @@ let client: LanguageClient;
let statusBarItem: StatusBarItem;
let currentModel: UI5Model | undefined;

export async function activate(context: ExtensionContext): Promise<void> {
// create the LanguageClient (+Server)
client = createLanguageClient(context);

// register semantic token provider
context.subscriptions.push(
languages.registerDocumentSemanticTokensProvider(
{ language: "xml" },
bindingSemanticTokensProvider,
bindingLegend
)
);

function init(context: ExtensionContext): void {
// create the StatusBarItem which displays the used UI5 version
statusBarItem = createStatusBarItem(context);

// show/hide and update the status bar
// create the LanguageClient (+Server)
client = createLanguageClient(context);

client.start().then(() => {
// show/hide and update the status bar
client.onNotification(
"UI5LanguageAssistant/ui5Model",
async (model: UI5Model): Promise<void> => await updateCurrentModel(model)
Expand All @@ -82,31 +72,56 @@ export async function activate(context: ExtensionContext): Promise<void> {
(error: Error) => handleContextError(error)
);
});
}

export async function activate(context: ExtensionContext): Promise<void> {
// complete initialization task asynchronously
init(context);

// register semantic token provider
context.subscriptions.push(
languages.registerDocumentSemanticTokensProvider(
{ language: "xml" },
bindingSemanticTokensProvider,
bindingLegend
)
);

window.onDidChangeActiveTextEditor(async () => {
await updateCurrentModel(undefined);
});

languages.registerDocumentFormattingEditProvider("xml", {
provideDocumentFormattingEdits(document: TextDocument): TextEdit[] {
if (isXMLView(document.uri.fsPath)) {
return formatDocument(document);
}
return [];
},
});
languages.registerDocumentRangeFormattingEditProvider("xml", {
provideDocumentRangeFormattingEdits(document, range, options): TextEdit[] {
if (isXMLView(document.uri.fsPath)) {
return formatRange(document, range, options);
}
return [];
},
});
client.start();
context.subscriptions.push(
languages.registerDocumentFormattingEditProvider("xml", {
provideDocumentFormattingEdits(document: TextDocument): TextEdit[] {
if (isXMLView(document.uri.fsPath)) {
return formatDocument(document);
}
return [];
},
})
);

const provider = await getManifestSchemaProvider(context);
context.subscriptions.push(
workspace.registerTextDocumentContentProvider(MANIFEST_SCHEMA, provider)
languages.registerDocumentRangeFormattingEditProvider("xml", {
provideDocumentRangeFormattingEdits(
document,
range,
options
): TextEdit[] {
if (isXMLView(document.uri.fsPath)) {
return formatRange(document, range, options);
}
return [];
},
})
);

context.subscriptions.push(
workspace.registerTextDocumentContentProvider(
MANIFEST_SCHEMA,
await getManifestSchemaProvider(context)
)
);
}

Expand Down
1 change: 1 addition & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ sonar.organization=sap-1
sonar.projectKey=SAP_ui5-language-assistant
sonar.sources=.
sonar.inclusions=**/*.ts
sonar.coverage.exclusions=packages/language-server/src/server.ts, packages/language-server/scripts/update-diagnostics-snapshots.js, packages/vscode-ui5-language-assistant/scripts/package-vsix.js, packages/vscode-ui5-language-assistant/src/extension.ts
sonar.exclusions=**/*.test.ts, **/test/**/*, **/test-packages/**/*, **/scripts/**/*.ts
sonar.cpd.exclusions=**/i18n.ts, **/*.test.ts, **/test/**/*, **/test-packages/**/*, **/scripts/**/*.ts
sonar.tests=.
Expand Down

0 comments on commit bfcac90

Please sign in to comment.