diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index a5c99b9c4..5b7508ff5 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,5 +1,2 @@ # schema.json for manifest packages/vscode-ui5-language-assistant/resources/ @sapirpol - -# register manifest.json schema in workspace configuration - theia workaround -packages/vscode-ui5-language-assistant/src/registerManifestSchema.ts @sapirpol @bd82 diff --git a/packages/vscode-ui5-language-assistant/src/extension.ts b/packages/vscode-ui5-language-assistant/src/extension.ts index 59b50e5d7..b591e7c64 100644 --- a/packages/vscode-ui5-language-assistant/src/extension.ts +++ b/packages/vscode-ui5-language-assistant/src/extension.ts @@ -10,7 +10,6 @@ import { SERVER_PATH, ServerInitializationOptions, } from "@ui5-language-assistant/language-server"; -import { registerManifestSchema } from "./registerManifestSchema"; let client: LanguageClient; @@ -51,13 +50,6 @@ export async function activate(context: ExtensionContext): Promise { clientOptions ); - // This is a workaround to config `manifest.json` schema. - // Theia has a bug which there is no support for `contributes.jsonValidation` - // - https://code.visualstudio.com/api/references/contribution-points#contributes.jsonValidation - if (process.env["THEIA_PARENT_PID"] !== undefined) { - registerManifestSchema(); - } - client.start(); } diff --git a/packages/vscode-ui5-language-assistant/src/manifestSchemaConfig.ts b/packages/vscode-ui5-language-assistant/src/manifestSchemaConfig.ts deleted file mode 100644 index 4d4fbe68f..000000000 --- a/packages/vscode-ui5-language-assistant/src/manifestSchemaConfig.ts +++ /dev/null @@ -1,20 +0,0 @@ -export interface IJSONValidationExtensionPoint { - fileMatch: string[]; - comment?: string; - url: string; -} - -export const MANIFEST_FILE_MATCH = "manifest.json"; -export const MANIFEST_COMMENT = - "Automatic configuration for manifest.json schema - added by UI5 Language Assistant"; - -export function getManifestSchemaConfigEntry(): IJSONValidationExtensionPoint { - const manifestSchemaConfig = { - fileMatch: [MANIFEST_FILE_MATCH], - comment: MANIFEST_COMMENT, - url: - "https://cdn.jsdelivr.net/gh/SAP/ui5-language-assistant/packages/vscode-ui5-language-assistant/resources/manifest-schema/rel-1.19/schema/schema.json", - }; - - return manifestSchemaConfig; -} diff --git a/packages/vscode-ui5-language-assistant/src/registerManifestSchema.ts b/packages/vscode-ui5-language-assistant/src/registerManifestSchema.ts deleted file mode 100644 index c9d68fd6b..000000000 --- a/packages/vscode-ui5-language-assistant/src/registerManifestSchema.ts +++ /dev/null @@ -1,98 +0,0 @@ -/* istanbul ignore file - temporary workaround */ -import { isArray, find, some, clone, findIndex } from "lodash"; -import { workspace } from "vscode"; -import { - getManifestSchemaConfigEntry, - IJSONValidationExtensionPoint, - MANIFEST_COMMENT, - MANIFEST_FILE_MATCH, -} from "./manifestSchemaConfig"; - -/** - * The configuration will be written in workspace.settings - */ -export function registerManifestSchema(): void { - const jsonSchemaConfig: - | IJSONValidationExtensionPoint - | undefined = workspace.getConfiguration().get("json.schemas"); - if (isArray(jsonSchemaConfig)) { - const previousConfigEntryIndex = getIndexOfPreviousConfigEntry( - jsonSchemaConfig - ); - if (previousConfigEntryIndex !== -1) { - updatePreviousConfigEntry(jsonSchemaConfig, previousConfigEntryIndex); - } else if (isMissingConfig(jsonSchemaConfig)) { - createConfig(jsonSchemaConfig); - } else { - // No change is needed - } - } -} - -function isMissingConfig( - jsonSchemaConfig: IJSONValidationExtensionPoint[] -): boolean { - const isMissingConfigEntry = - find( - jsonSchemaConfig, - (jsonSchemaConfigEntry: IJSONValidationExtensionPoint) => { - return some( - jsonSchemaConfigEntry.fileMatch, - (fileMatchEntry) => fileMatchEntry === MANIFEST_FILE_MATCH - ); - } - ) === undefined; - - return isMissingConfigEntry; -} - -function createConfig(jsonSchemaConfig: IJSONValidationExtensionPoint[]): void { - const configEntry = getManifestSchemaConfigEntry(); - const updatedSchemaConfig = clone(jsonSchemaConfig); - updatedSchemaConfig.push(configEntry); - - configureSchemaInWorkspaceSettings(updatedSchemaConfig); -} - -function getIndexOfPreviousConfigEntry( - jsonSchemaConfig: IJSONValidationExtensionPoint[] -): number { - const previousConfigEntryIndex = findIndex( - jsonSchemaConfig, - (jsonSchemaConfigEntry: IJSONValidationExtensionPoint) => { - if (jsonSchemaConfigEntry.fileMatch.length === 1) { - // we are looking for exact match to be sure we are only changing 'settings.json' we added - return some( - jsonSchemaConfigEntry.fileMatch, - (fileMatchEntry) => - fileMatchEntry === MANIFEST_FILE_MATCH && - jsonSchemaConfigEntry.comment === MANIFEST_COMMENT - ); - } - - return false; - } - ); - - return previousConfigEntryIndex; -} - -function updatePreviousConfigEntry( - jsonSchemaConfig: IJSONValidationExtensionPoint[], - previusConfigEntryIndex: number -): void { - const updatedSchemaConfig = clone(jsonSchemaConfig); - updatedSchemaConfig[previusConfigEntryIndex] = getManifestSchemaConfigEntry(); - - configureSchemaInWorkspaceSettings(updatedSchemaConfig); -} - -function configureSchemaInWorkspaceSettings( - updatedSchemaConfig: IJSONValidationExtensionPoint[] -): void { - // We pass 'true' for global settings - // - https://code.visualstudio.com/api/references/vscode-api#WorkspaceConfiguration - workspace - .getConfiguration() - .update("json.schemas", updatedSchemaConfig, true); -} diff --git a/packages/vscode-ui5-language-assistant/test/unit/registerManifestSchema-spec.ts b/packages/vscode-ui5-language-assistant/test/unit/registerManifestSchema-spec.ts deleted file mode 100644 index a4ac754ec..000000000 --- a/packages/vscode-ui5-language-assistant/test/unit/registerManifestSchema-spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { expect } from "chai"; -import { getManifestSchemaConfigEntry } from "../../src/manifestSchemaConfig"; - -/** - * fileMatch / comment values used to **identify** workspace settings - * that have been automatically added by this vscode extension. - */ -describe("the manifest schema entry configuration", () => { - it("file match must never be changed", () => { - const manifestSchemaConfig = getManifestSchemaConfigEntry(); - expect(manifestSchemaConfig.fileMatch).to.exist; - expect(manifestSchemaConfig.fileMatch).to.have.length(1); - expect(manifestSchemaConfig.fileMatch[0]).to.equal("manifest.json"); - }); - - it("comment must never be changed", () => { - const expectedComment = - "Automatic configuration for manifest.json schema - added by UI5 Language Assistant"; - const manifestSchemaConfig = getManifestSchemaConfigEntry(); - expect(manifestSchemaConfig.comment).to.exist; - expect(manifestSchemaConfig.comment).to.equal(expectedComment); - }); -});