Skip to content

Commit 6fe3662

Browse files
authored
fix: lsp for adaption project - first iteration (#733)
* fix: lsp for adaption project - first iteration * fix: enhance get context api test
1 parent 1e41b87 commit 6fe3662

File tree

24 files changed

+598
-5
lines changed

24 files changed

+598
-5
lines changed

.changeset/nasty-bugs-chew.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch
3+
"vscode-ui5-language-assistant": patch
4+
"@ui5-language-assistant/language-server": patch
5+
"@ui5-language-assistant/test-framework": patch
6+
"@ui5-language-assistant/context": patch
7+
---
8+
9+
fix: lsp for adaption project - first iteration

packages/context/src/adp-manifest.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import findUp from "find-up";
2+
import { FileName } from "@sap-ux/project-access";
3+
/**
4+
* Get path of a manifest.appdescr_variant file for adaption project.
5+
* @param documentPath path to a file e.g. absolute/path/webapp/ext/main/Main.view.xml
6+
*/
7+
export async function finAdpdManifestPath(
8+
documentPath: string
9+
): Promise<string | undefined> {
10+
return findUp(FileName.ManifestAppDescrVar, { cwd: documentPath });
11+
}

packages/context/src/api.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
getManifestDetails,
55
getUI5Manifest,
66
} from "./manifest";
7+
import { finAdpdManifestPath } from "./adp-manifest";
78
import { getServices } from "./services";
89
import { Context } from "./types";
910
import { getSemanticModel } from "./ui5-model";
@@ -47,7 +48,8 @@ export async function getContext(
4748
): Promise<Context | Error> {
4849
try {
4950
const manifestDetails = await getManifestDetails(documentPath);
50-
const manifest = await getUI5Manifest(manifestDetails.manifestPath);
51+
let manifestPath = manifestDetails.manifestPath;
52+
const manifest = await getUI5Manifest(manifestPath);
5153
let minUI5Version = manifestDetails.minUI5Version;
5254
if (manifest) {
5355
minUI5Version = getMinimumUI5Version(manifest);
@@ -61,7 +63,12 @@ export async function getContext(
6163
);
6264
const services = await getServices(documentPath);
6365
const customViewId = await getCustomViewId(documentPath);
64-
const manifestPath = manifestDetails.manifestPath;
66+
if (!manifestPath) {
67+
const adpManifestPath = await finAdpdManifestPath(documentPath);
68+
if (adpManifestPath) {
69+
manifestPath = adpManifestPath;
70+
}
71+
}
6572
const viewFiles = await getViewFiles({
6673
manifestPath,
6774
documentPath,

packages/context/src/utils/view-files.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ export async function getViewFiles(param: {
7070
}
7171

7272
const files = {};
73-
await processViewFiles(join(manifestPath, ".."), files);
73+
if (!manifestPath) {
74+
// a project without manifest.json or manifest.appdescr_variant file. Only support for current view file
75+
const ast = await createDocumentAst(documentPath);
76+
files[documentPath] = ast;
77+
} else {
78+
// find all view files
79+
await processViewFiles(join(manifestPath, ".."), files);
80+
}
81+
7482
cache.setViewFiles(manifestPath, files);
7583
return files;
7684
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { join } from "path";
2+
import {
3+
Config,
4+
ProjectName,
5+
ProjectType,
6+
TestFramework,
7+
} from "@ui5-language-assistant/test-framework";
8+
import { finAdpdManifestPath } from "../../src/adp-manifest";
9+
10+
describe("adp-manifest", () => {
11+
let framework: TestFramework;
12+
beforeAll(function () {
13+
const useConfig: Config = {
14+
projectInfo: {
15+
name: ProjectName.cap,
16+
type: ProjectType.CAP,
17+
npmInstall: true,
18+
},
19+
};
20+
framework = new TestFramework(useConfig);
21+
});
22+
23+
afterEach(() => {
24+
jest.restoreAllMocks();
25+
});
26+
describe("finAdpdManifestPath", () => {
27+
beforeAll(function () {
28+
const useConfig: Config = {
29+
projectInfo: {
30+
name: ProjectName.adp,
31+
type: ProjectType.ADP,
32+
npmInstall: false,
33+
},
34+
};
35+
framework = new TestFramework(useConfig);
36+
});
37+
it("undefined", async () => {
38+
const root = framework.getProjectRoot();
39+
const result = await finAdpdManifestPath(root);
40+
expect(result).toBeUndefined();
41+
});
42+
it("path to manifest.appdescr_variant file", async () => {
43+
const root = framework.getProjectRoot();
44+
const pathSegments = [
45+
"webapp",
46+
"changes",
47+
"fragments",
48+
"actionToolbar.fragment.xml",
49+
];
50+
const docPath = join(root, ...pathSegments);
51+
const result = await finAdpdManifestPath(docPath);
52+
expect(result).toEqual(join(root, "webapp", "manifest.appdescr_variant"));
53+
});
54+
});
55+
});

packages/context/test/unit/api.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as manifest from "../../src/manifest";
2+
import * as adpManifest from "../../src/adp-manifest";
23
import * as ui5Yaml from "../../src/ui5-yaml";
34
import * as ui5Model from "../../src/ui5-model";
45
import * as services from "../../src/services";
@@ -51,6 +52,9 @@ describe("context", () => {
5152
const getServicesStub = jest
5253
.spyOn(services, "getServices")
5354
.mockResolvedValue({});
55+
const finAdpdManifestPathStub = jest
56+
.spyOn(adpManifest, "finAdpdManifestPath")
57+
.mockResolvedValue("/path/to/app/variant");
5458
const getViewFilesStub = jest
5559
.spyOn(viewFiles, "getViewFiles")
5660
.mockResolvedValue({});
@@ -67,6 +71,7 @@ describe("context", () => {
6771
expect(getYamlDetailsStub).toHaveBeenCalled();
6872
expect(getSemanticModelStub).toHaveBeenCalled();
6973
expect(getServicesStub).toHaveBeenCalled();
74+
expect(finAdpdManifestPathStub).toHaveBeenCalled();
7075
expect(getViewFilesStub).toHaveBeenCalled();
7176
expect(getControlIdsStub).toHaveBeenCalled();
7277
expect(result).toContainAllKeys([

packages/context/test/unit/loader.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import * as manifest from "../../src/manifest";
1111
import * as projectUtils from "../../src/utils/project";
1212
import { cache } from "../../src/cache";
1313
import { Manifest } from "@sap-ux/project-access";
14-
import { ProjectKind, UI5_PROJECT_TYPE } from "../../src/types";
14+
import {
15+
ProjectKind,
16+
UI5_PROJECT_TYPE,
17+
ProjectType as ProjType,
18+
} from "../../src/types";
1519
import { getProjectData } from "./utils";
1620
import { getManifestDetails, getUI5Manifest } from "../../src/manifest";
1721
import { getApp } from "../../src/loader";
@@ -156,7 +160,7 @@ describe("loader", () => {
156160
projectRoot
157161
);
158162
const projectInfo = { kind: "Java", type: "CAP" } as {
159-
type: ProjectType;
163+
type: ProjType;
160164
kind: ProjectKind;
161165
};
162166
const capProject = await loader.getCAPProject(

packages/context/test/unit/utils/view-files.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,23 @@ describe("view-files", () => {
104104
expect(Object.keys(viewFiles).length).toBeGreaterThan(1);
105105
expect(viewFiles[documentPath]).toBeDefined();
106106
});
107+
it("get view files - no manifest path", async () => {
108+
// arrange
109+
cache.reset();
110+
const getViewFilesStub = jest
111+
.spyOn(cache, "getViewFiles")
112+
.mockReturnValue({});
113+
const projectRoot = testFramework.getProjectRoot();
114+
const documentPath = getDocumentPath(projectRoot);
115+
const manifestPath = "";
116+
// act
117+
const viewFiles = await getViewFiles({
118+
manifestPath,
119+
documentPath,
120+
});
121+
// assert
122+
expect(getViewFilesStub).toHaveBeenCalledTimes(1);
123+
expect(Object.keys(viewFiles).length).toEqual(1);
124+
expect(viewFiles[documentPath]).toBeDefined();
125+
});
107126
});

packages/language-server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@types/tmp": "0.2.0",
5858
"@ui5-language-assistant/semantic-model-types": "4.0.11",
5959
"@ui5-language-assistant/test-utils": "4.0.16",
60+
"@ui5-language-assistant/test-framework": "4.0.12",
6061
"string-replace-loader": "3.1.0",
6162
"vscode-languageserver-types": "3.17.2"
6263
},
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`xml view diagnostics adaptation project diagnostics for duplicate ids - duplicates 1`] = `
4+
Array [
5+
Object {
6+
"message": "Select a unique ID. The current \\"_IDGenText\\" ID has already been used.",
7+
"range": Object {
8+
"end": Object {
9+
"character": 25,
10+
"line": 3,
11+
},
12+
"start": Object {
13+
"character": 13,
14+
"line": 3,
15+
},
16+
},
17+
"relatedInformation": Array [
18+
Object {
19+
"location": Object {
20+
"range": Object {
21+
"end": Object {
22+
"character": 25,
23+
"line": 3,
24+
},
25+
"start": Object {
26+
"character": 13,
27+
"line": 3,
28+
},
29+
},
30+
"uri": "filterBar.fragment.xml",
31+
},
32+
"message": "An identical ID is also used here.",
33+
},
34+
],
35+
"severity": 1,
36+
"source": "UI5 Language Assistant",
37+
},
38+
Object {
39+
"message": "Select a unique ID. The current \\"_IDGenButton\\" ID has already been used.",
40+
"range": Object {
41+
"end": Object {
42+
"character": 29,
43+
"line": 4,
44+
},
45+
"start": Object {
46+
"character": 15,
47+
"line": 4,
48+
},
49+
},
50+
"relatedInformation": Array [
51+
Object {
52+
"location": Object {
53+
"range": Object {
54+
"end": Object {
55+
"character": 29,
56+
"line": 4,
57+
},
58+
"start": Object {
59+
"character": 15,
60+
"line": 4,
61+
},
62+
},
63+
"uri": "filterBar.fragment.xml",
64+
},
65+
"message": "An identical ID is also used here.",
66+
},
67+
],
68+
"severity": 1,
69+
"source": "UI5 Language Assistant",
70+
},
71+
]
72+
`;

0 commit comments

Comments
 (0)