Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"name": "Launch Client",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}/packages/vscode-ui5-language-assistant"
"--extensionDevelopmentPath=${workspaceRoot}/packages/vscode-ui5-language-assistant",
"--disable-extensions"
],
"outFiles": [
"${workspaceRoot}/packages/vscode-ui5-language-assistant/lib/src/**/*.js"
Expand Down
25 changes: 17 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,24 @@
"build:quick": "lerna run compile && lerna run bundle && lerna run package",
"release:version": "lerna version --force-publish",
"release:publish": "lerna publish from-git --yes",
"ci": "npm-run-all format:validate ci:subpackages coverage:merge legal:*",
"compile": "yarn run clean && tsc --build",
"compile": "turbo run compile",
"ci": "turbo run ci",
"preci": "turbo run coverage",
"compile:watch": "yarn run clean && tsc --build --watch",
"format:fix": "prettier --write \"**/*.@(js|ts|json|md)\" --ignore-path=.gitignore",
"format:validate": "prettier --check \"**/*.@(js|ts|json|md)\" --ignore-path=.gitignore",
"lint": "eslint . --ext .ts --fix --max-warnings=0 --ignore-path=.gitignore",
"lint": "turbo run lint",
"ci:subpackages": "lerna run ci",
"test": "lerna run test",
"coverage": "lerna run coverage",
"coverage:merge": "node ./scripts/merge-coverage",
"clean": "lerna run clean",
"test": "turbo run test",
"pretest": "turbo run compile",
"precoverage": "turbo run pretest",
"prebuild": "yarn run clean",
"prebundle": "turbo run clean",
"build": "turbo run build",
"bundle": "turbo run bundle",
"package": "turbo run package",
"format:validate": "turbo run format:validate",
"coverage": "turbo run coverage",
"clean": "turbo run clean",
"update-snapshots": "lerna run update-snapshots",
"legal:delete": "lerna exec \"shx rm -rf .reuse LICENSES\" || true",
"legal:copy": "lerna exec \"shx cp -r ../../.reuse .reuse && shx cp -r ../../LICENSES LICENSES\"",
Expand All @@ -48,6 +55,7 @@
"@typescript-eslint/eslint-plugin": "4.14.0",
"@typescript-eslint/parser": "4.14.0",
"chai": "4.2.0",
"turbo": "^1.4.5",
"conventional-changelog-cli": "2.1.1",
"coveralls": "3.1.0",
"cz-conventional-changelog": "3.3.0",
Expand All @@ -72,6 +80,7 @@
"sinon": "9.2.3",
"sinon-chai": "3.5.0",
"source-map-support": "0.5.19",
"turborepo": "^0.0.1",
"typescript": "3.9.7",
"webpack": "5.36.2",
"webpack-cli": "4.4.0"
Expand Down
9 changes: 8 additions & 1 deletion packages/language-server/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Absolute path to the server's "main" module
* This is useful when launching the server in a separate process (e.g via spawn).
*/
import { LogLevel } from "@vscode-logging/types";

import { LogLevel } from "@vscode-logging/types";
export declare const SERVER_PATH: string;

export type ServerInitializationOptions = {
Expand All @@ -25,6 +25,13 @@ export type ServerInitializationOptions = {
logLevel?: LogLevel;
};

export function getNodeName(
text: string,
offsetAt: number,
cachePath?: string,
framework?: string,
ui5Version?: string
): Promise<string | undefined>;
export type FetchResponse = {
ok: boolean;
status: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"scripts": {
"ci": "npm-run-all clean compile lint coverage bundle",
"clean": "rimraf ./dist ./lib ./coverage ./nyc_output",
"compile": "yarn run clean && tsc -p .",
"compile": "tsc -p .",
"compile:watch": "tsc -p . --watch",
"lint": "eslint . --ext .ts --max-warnings=0 --ignore-path=../../.gitignore",
"test": "mocha",
Expand Down
23 changes: 23 additions & 0 deletions packages/language-server/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { resolve } from "path";
import { existsSync } from "fs";
import { getNodeDetail, getUI5NodeName } from "./documentation";

// for use in productive flows
const bundledPath = resolve(__dirname, "..", "..", "dist", "server.js");
Expand All @@ -19,3 +20,25 @@ export const SERVER_PATH: string = isDevelopmentRun
? /* istanbul ignore else - no tests (yet?) on bundled artifacts */
sourcesPath
: bundledPath;

export async function getNodeName(
text: string,
offsetAt: number,
cachePath?: string | undefined,
framework?: string | undefined,
ui5Version?: string | undefined
): Promise<string | undefined> {
const ui5Node = await getUI5NodeName(
offsetAt,
text,
undefined,
cachePath,
framework,
ui5Version
);
return ui5Node
? ui5Node.kind !== "UI5Class"
? `${ui5Node.parent?.library}.${ui5Node.parent?.name}`
: getNodeDetail(ui5Node)
: undefined;
}
32 changes: 32 additions & 0 deletions packages/language-server/src/documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import {
getLink,
} from "@ui5-language-assistant/logic-utils";
import { GENERATED_LIBRARY } from "@ui5-language-assistant/semantic-model";
import { DocumentCstNode, parse } from "@xml-tools/parser";
import { buildAst } from "@xml-tools/ast";
import { astPositionAtOffset } from "@xml-tools/ast-position";
import { findUI5HoverNodeAtOffset } from "@ui5-language-assistant/xml-views-tooltip";
import { getSemanticModel } from "./ui5-model";

export function getNodeDocumentation(
node: BaseUI5Node,
Expand Down Expand Up @@ -108,3 +113,30 @@ export function getNodeDetail(node: BaseUI5Node): string {
return node.name;
}
}

export async function getUI5NodeName(
offsetAt: number,
text: string,
model?: UI5SemanticModel,
cachePath?: string,
framework?: string,
ui5Version?: string
): Promise<BaseUI5Node | undefined> {
const documentText = text;
const { cst, tokenVector } = parse(documentText);
const ast = buildAst(cst as DocumentCstNode, tokenVector);
const offset = offsetAt;
const astPosition = astPositionAtOffset(ast, offset);
if (!model) {
model = await fetchModel(cachePath, framework, ui5Version);
}
if (astPosition !== undefined) {
return findUI5HoverNodeAtOffset(astPosition, model);
}
return undefined;
}

async function fetchModel(cachePath, framework, ui5Version) {
const ui5Model = await getSemanticModel(cachePath, framework, ui5Version);
return ui5Model;
}
33 changes: 15 additions & 18 deletions packages/language-server/src/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,30 @@ import {
MarkupContent,
MarkupKind,
} from "vscode-languageserver";
import { parse, DocumentCstNode } from "@xml-tools/parser";
import { buildAst } from "@xml-tools/ast";
import { astPositionAtOffset } from "@xml-tools/ast-position";
import {
UI5SemanticModel,
BaseUI5Node,
} from "@ui5-language-assistant/semantic-model-types";
import { findUI5HoverNodeAtOffset } from "@ui5-language-assistant/xml-views-tooltip";
import { getNodeDocumentation, getNodeDetail } from "./documentation";
import {
getNodeDocumentation,
getNodeDetail,
getUI5NodeName,
} from "./documentation";
import { track } from "./swa";

export function getHoverResponse(
export async function getHoverResponse(
model: UI5SemanticModel,
textDocumentPosition: TextDocumentPositionParams,
document: TextDocument
): Hover | undefined {
const documentText = document.getText();
const { cst, tokenVector } = parse(documentText);
const ast = buildAst(cst as DocumentCstNode, tokenVector);
const offset = document.offsetAt(textDocumentPosition.position);
const astPosition = astPositionAtOffset(ast, offset);
if (astPosition !== undefined) {
const ui5Node = findUI5HoverNodeAtOffset(astPosition, model);
if (ui5Node !== undefined) {
track("XML_UI5_DOC_HOVER", ui5Node.kind);
return transformToLspHover(ui5Node, model);
}
): Promise<Hover | undefined> {
const ui5Node = await getUI5NodeName(
document.offsetAt(textDocumentPosition.position),
document.getText(),
model
);
if (ui5Node !== undefined) {
track("XML_UI5_DOC_HOVER", ui5Node.kind);
return transformToLspHover(ui5Node, model);
}

return undefined;
Expand Down
49 changes: 49 additions & 0 deletions packages/language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
InitializeParams,
Hover,
DidChangeConfigurationNotification,
DefinitionParams,
} from "vscode-languageserver";
import { URI } from "vscode-uri";
import { TextDocument } from "vscode-languageserver-textdocument";
Expand Down Expand Up @@ -94,6 +95,8 @@ connection.onInitialize((params: InitializeParams) => {
commands.QUICK_FIX_STABLE_ID_FILE_ERRORS.name,
],
},
referencesProvider: false,
definitionProvider: true,
},
};
});
Expand All @@ -108,6 +111,46 @@ connection.onInitialized(async () => {
}
});

connection.onDefinition(async (params: DefinitionParams) => {
const documentUri = params.textDocument.uri;
const document = documents.get(documentUri);
if (document) {
const documentPath = URI.parse(documentUri).fsPath;
const minUI5Version = getMinUI5VersionForXMLFile(documentPath);
const framework = getUI5FrameworkForXMLFile(documentPath);
const model = await getSemanticModel(
initializationOptions?.modelCachePath,
framework,
minUI5Version
);

const ui5Url = getCDNBaseUrl(framework, model.version);

getLogger().debug("`onDefinition` event", {
url: ui5Url,
});

// const documentUri = params.textDocument.uri;
// const document = documents.get(documentUri);
// if (document) {
// const documentPath = URI.parse(documentUri).fsPath;
// const minUI5Version = getMinUI5VersionForXMLFile(documentPath);
// const framework = getUI5FrameworkForXMLFile(documentPath);
// const model = await getSemanticModel(
// initializationOptions?.modelCachePath,
// framework,
// minUI5Version
// );
// const ui5Url = getCDNBaseUrl(framework, model.version)

// }
connection.sendNotification("UI5LanguageAssistant/ui5Definition", {
url: ui5Url,
});
}
return null;
});

connection.onCompletion(
async (
textDocumentPosition: TextDocumentPositionParams
Expand All @@ -128,6 +171,7 @@ connection.onCompletion(
minUI5Version
);
connection.sendNotification("UI5LanguageAssistant/ui5Model", {
cachePath: initializationOptions?.modelCachePath,
url: getCDNBaseUrl(framework, model.version),
framework,
version: model.version,
Expand Down Expand Up @@ -172,6 +216,7 @@ connection.onHover(
minUI5Version
);
connection.sendNotification("UI5LanguageAssistant/ui5Model", {
cachePath: initializationOptions?.modelCachePath,
url: getCDNBaseUrl(framework, ui5Model.version),
framework,
version: ui5Model.version,
Expand Down Expand Up @@ -226,6 +271,8 @@ documents.onDidChangeContent(async (changeEvent) => {
minUI5Version
);
connection.sendNotification("UI5LanguageAssistant/ui5Model", {
cachePath: initializationOptions?.modelCachePath,

url: getCDNBaseUrl(framework, ui5Model.version),
framework,
version: ui5Model.version,
Expand Down Expand Up @@ -258,6 +305,8 @@ connection.onCodeAction(async (params) => {
minUI5Version
);
connection.sendNotification("UI5LanguageAssistant/ui5Model", {
cachePath: initializationOptions?.modelCachePath,

url: getCDNBaseUrl(framework, ui5Model.version),
framework,
version: ui5Model.version,
Expand Down
Loading