-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: lsp for adaption project - first iteration (#733)
* fix: lsp for adaption project - first iteration * fix: enhance get context api test
- Loading branch information
1 parent
1e41b87
commit 6fe3662
Showing
24 changed files
with
598 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch | ||
"vscode-ui5-language-assistant": patch | ||
"@ui5-language-assistant/language-server": patch | ||
"@ui5-language-assistant/test-framework": patch | ||
"@ui5-language-assistant/context": patch | ||
--- | ||
|
||
fix: lsp for adaption project - first iteration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import findUp from "find-up"; | ||
import { FileName } from "@sap-ux/project-access"; | ||
/** | ||
* Get path of a manifest.appdescr_variant file for adaption project. | ||
* @param documentPath path to a file e.g. absolute/path/webapp/ext/main/Main.view.xml | ||
*/ | ||
export async function finAdpdManifestPath( | ||
documentPath: string | ||
): Promise<string | undefined> { | ||
return findUp(FileName.ManifestAppDescrVar, { cwd: documentPath }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { join } from "path"; | ||
import { | ||
Config, | ||
ProjectName, | ||
ProjectType, | ||
TestFramework, | ||
} from "@ui5-language-assistant/test-framework"; | ||
import { finAdpdManifestPath } from "../../src/adp-manifest"; | ||
|
||
describe("adp-manifest", () => { | ||
let framework: TestFramework; | ||
beforeAll(function () { | ||
const useConfig: Config = { | ||
projectInfo: { | ||
name: ProjectName.cap, | ||
type: ProjectType.CAP, | ||
npmInstall: true, | ||
}, | ||
}; | ||
framework = new TestFramework(useConfig); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
describe("finAdpdManifestPath", () => { | ||
beforeAll(function () { | ||
const useConfig: Config = { | ||
projectInfo: { | ||
name: ProjectName.adp, | ||
type: ProjectType.ADP, | ||
npmInstall: false, | ||
}, | ||
}; | ||
framework = new TestFramework(useConfig); | ||
}); | ||
it("undefined", async () => { | ||
const root = framework.getProjectRoot(); | ||
const result = await finAdpdManifestPath(root); | ||
expect(result).toBeUndefined(); | ||
}); | ||
it("path to manifest.appdescr_variant file", async () => { | ||
const root = framework.getProjectRoot(); | ||
const pathSegments = [ | ||
"webapp", | ||
"changes", | ||
"fragments", | ||
"actionToolbar.fragment.xml", | ||
]; | ||
const docPath = join(root, ...pathSegments); | ||
const result = await finAdpdManifestPath(docPath); | ||
expect(result).toEqual(join(root, "webapp", "manifest.appdescr_variant")); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages/language-server/test/unit/__snapshots__/xml-view-diagnostics.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`xml view diagnostics adaptation project diagnostics for duplicate ids - duplicates 1`] = ` | ||
Array [ | ||
Object { | ||
"message": "Select a unique ID. The current \\"_IDGenText\\" ID has already been used.", | ||
"range": Object { | ||
"end": Object { | ||
"character": 25, | ||
"line": 3, | ||
}, | ||
"start": Object { | ||
"character": 13, | ||
"line": 3, | ||
}, | ||
}, | ||
"relatedInformation": Array [ | ||
Object { | ||
"location": Object { | ||
"range": Object { | ||
"end": Object { | ||
"character": 25, | ||
"line": 3, | ||
}, | ||
"start": Object { | ||
"character": 13, | ||
"line": 3, | ||
}, | ||
}, | ||
"uri": "filterBar.fragment.xml", | ||
}, | ||
"message": "An identical ID is also used here.", | ||
}, | ||
], | ||
"severity": 1, | ||
"source": "UI5 Language Assistant", | ||
}, | ||
Object { | ||
"message": "Select a unique ID. The current \\"_IDGenButton\\" ID has already been used.", | ||
"range": Object { | ||
"end": Object { | ||
"character": 29, | ||
"line": 4, | ||
}, | ||
"start": Object { | ||
"character": 15, | ||
"line": 4, | ||
}, | ||
}, | ||
"relatedInformation": Array [ | ||
Object { | ||
"location": Object { | ||
"range": Object { | ||
"end": Object { | ||
"character": 29, | ||
"line": 4, | ||
}, | ||
"start": Object { | ||
"character": 15, | ||
"line": 4, | ||
}, | ||
}, | ||
"uri": "filterBar.fragment.xml", | ||
}, | ||
"message": "An identical ID is also used here.", | ||
}, | ||
], | ||
"severity": 1, | ||
"source": "UI5 Language Assistant", | ||
}, | ||
] | ||
`; |
114 changes: 114 additions & 0 deletions
114
packages/language-server/test/unit/xml-view-diagnostics.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { getXMLViewIdDiagnostics } from "../../src/xml-view-diagnostics"; | ||
import { | ||
Config, | ||
ProjectName, | ||
ProjectType, | ||
TestFramework, | ||
} from "@ui5-language-assistant/test-framework"; | ||
import { | ||
Context, | ||
getContext, | ||
isContext, | ||
cache, | ||
} from "@ui5-language-assistant/context"; | ||
import { join, basename } from "path"; | ||
|
||
describe("xml view diagnostics", () => { | ||
describe("adaptation project", () => { | ||
let framework: TestFramework; | ||
let context: Context; | ||
beforeAll(async () => { | ||
const useConfig: Config = { | ||
projectInfo: { | ||
name: ProjectName.adp, | ||
type: ProjectType.ADP, | ||
npmInstall: false, | ||
}, | ||
}; | ||
framework = new TestFramework(useConfig); | ||
}); | ||
beforeEach(() => { | ||
// reset to avoid side effects | ||
cache.reset(); | ||
}); | ||
it("diagnostics for duplicate ids - no duplicate", async () => { | ||
// arrange | ||
const root = framework.getProjectRoot(); | ||
const snippet = ` | ||
<!-- Use stable and unique IDs!--> | ||
<core:FragmentDefinition xmlns:core='sap.ui.core' xmlns='sap.m'> | ||
<Text id="_IDGenText" > | ||
<Button id="_IDGenButton" /> | ||
</core:FragmentDefinition>`; | ||
const pathSegments = [ | ||
"webapp", | ||
"changes", | ||
"fragments", | ||
"actionToolbar.fragment.xml", | ||
]; | ||
await framework.updateFile(pathSegments, snippet); | ||
const docPath = join(root, ...pathSegments); | ||
const ctx = await getContext(docPath); | ||
if (isContext(ctx)) { | ||
context = ctx; | ||
} else { | ||
throw new Error("Failed to build context...."); | ||
} | ||
const { document } = framework.toVscodeTextDocument( | ||
framework.getFileUri(pathSegments), | ||
snippet, | ||
0 | ||
); | ||
// act | ||
const result = getXMLViewIdDiagnostics({ document, context }); | ||
// assert | ||
expect(result).toEqual([]); | ||
}); | ||
it("diagnostics for duplicate ids - duplicates", async () => { | ||
// arrange | ||
const root = framework.getProjectRoot(); | ||
const snippet = ` | ||
<!-- Use stable and unique IDs!--> | ||
<core:FragmentDefinition xmlns:core='sap.ui.core' xmlns='sap.m'> | ||
<Text id="_IDGenText" > | ||
<Button id="_IDGenButton" /> | ||
</core:FragmentDefinition>`; | ||
const pathSegments = [ | ||
"webapp", | ||
"changes", | ||
"fragments", | ||
"actionToolbar.fragment.xml", | ||
]; | ||
await framework.updateFile(pathSegments, snippet); | ||
const pathSegments02 = [ | ||
"webapp", | ||
"changes", | ||
"fragments", | ||
"filterBar.fragment.xml", | ||
]; | ||
await framework.updateFile(pathSegments02, snippet); | ||
const docPath = join(root, ...pathSegments); | ||
const ctx = await getContext(docPath); | ||
if (isContext(ctx)) { | ||
context = ctx; | ||
} else { | ||
throw new Error("Failed to build context...."); | ||
} | ||
const { document } = framework.toVscodeTextDocument( | ||
framework.getFileUri(pathSegments), | ||
snippet, | ||
0 | ||
); | ||
// act | ||
const result = getXMLViewIdDiagnostics({ document, context }); | ||
// adapt uri | ||
result.map((i) => | ||
i.relatedInformation?.map((j) => { | ||
j.location.uri = basename(j.location.uri); | ||
}) | ||
); | ||
// assert | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.