Skip to content

Commit

Permalink
fix: use file uri for definition (#704)
Browse files Browse the repository at this point in the history
* fix: file uri for location

* fix: change set

* fix: review comment
  • Loading branch information
marufrasully authored Apr 10, 2024
1 parent 4474d20 commit 5b190da
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 41 deletions.
7 changes: 7 additions & 0 deletions .changeset/itchy-moles-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch
"vscode-ui5-language-assistant": patch
"@ui5-language-assistant/xml-views-definition": patch
---

Fix: Use file uri for definition
16 changes: 4 additions & 12 deletions packages/xml-views-definition/src/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,15 @@ export async function getControllerLocation(
if (!fileUri) {
return [];
}
return [
{
uri: fileUri,
range: { start: position, end: position },
},
];
const loc = Location.create(fileUri, { start: position, end: position });
return [loc];
}

// handle dot notation
const fileUri = await buildFileUri(id, value, manifestPath, exts);
if (!fileUri) {
return [];
}
return [
{
uri: fileUri,
range: { start: position, end: position },
},
];
const loc = Location.create(fileUri, { start: position, end: position });
return [loc];
}
3 changes: 2 additions & 1 deletion packages/xml-views-definition/src/utils/file.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { access, constants } from "fs";
import { join, dirname } from "path";
import { URI } from "vscode-uri";

/**
* Check if path exists on file system.
Expand Down Expand Up @@ -44,7 +45,7 @@ export async function buildFileUri(
for (const ext of exts) {
const filePath = `${absolutePath}${ext}`;
if (await pathExists(filePath)) {
return filePath;
return URI.file(filePath).toString();
}
}
}
29 changes: 17 additions & 12 deletions packages/xml-views-definition/test/unit/controller/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as fs from "fs";
import * as context from "@ui5-language-assistant/context";
import { getControllerLocation } from "../../../src/controller";
import { join } from "path";
import { URI } from "vscode-uri";

describe("index", () => {
let testFramework: TestFramework;
Expand Down Expand Up @@ -173,12 +174,14 @@ describe("index", () => {
// assert
expect(result).toEqual([
{
uri: join(
testFramework.getProjectRoot(),
"src",
"controller",
"App.controller.ts"
),
uri: URI.file(
join(
testFramework.getProjectRoot(),
"src",
"controller",
"App.controller.ts"
)
).toString(),
range: { start: position, end: position },
},
]);
Expand Down Expand Up @@ -281,12 +284,14 @@ describe("index", () => {
// assert
expect(result).toEqual([
{
uri: join(
testFramework.getProjectRoot(),
"src",
"controller",
"App.controller.ts"
),
uri: URI.file(
join(
testFramework.getProjectRoot(),
"src",
"controller",
"App.controller.ts"
)
).toString(),
range: { start: position, end: position },
},
]);
Expand Down
32 changes: 16 additions & 16 deletions packages/xml-views-definition/test/unit/utils/file.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { pathExists, buildFileUri } from "../../../src/utils";
import { join } from "path";
import { URI } from "vscode-uri";
const getExpectedFileUri = (parts: string[]) =>
URI.file(join(__dirname, ...parts)).toString();

describe("file", () => {
describe("pathExists", () => {
Expand Down Expand Up @@ -27,13 +30,12 @@ describe("file", () => {
// arrange
const namespace = "sap.ui.demo.walkthrough";
const value = "sap.ui.demo.walkthrough.controller.App";
const expectedFileUri = join(
__dirname,
const expectedFileUri = getExpectedFileUri([
"..",
"data",
"controller",
"App.controller.js"
);
"App.controller.js",
]);
// act
const result = await buildFileUri(
namespace,
Expand All @@ -48,13 +50,12 @@ describe("file", () => {
// arrange
const namespace = "sap.ui.demo.walkthrough";
const value = "sap.ui.demo.walkthrough.controller.AppHelper";
const expectedFileUri = join(
__dirname,
const expectedFileUri = getExpectedFileUri([
"..",
"data",
"controller",
"AppHelper.js"
);
"AppHelper.js",
]);
// act
const result = await buildFileUri(
namespace,
Expand All @@ -70,13 +71,12 @@ describe("file", () => {
// arrange
const namespace = "sap.ui.demo.walkthrough";
const value = "sap.ui.demo.walkthrough.controller.Helper";
const expectedFileUri = join(
__dirname,
const expectedFileUri = getExpectedFileUri([
"..",
"data",
"controller",
"Helper.controller.ts"
);
"Helper.controller.ts",
]);
// act
const result = await buildFileUri(
namespace,
Expand All @@ -91,13 +91,13 @@ describe("file", () => {
// arrange
const namespace = "sap.ui.demo.walkthrough";
const value = "sap.ui.demo.walkthrough.controller.Handler";
const expectedFileUri = join(
__dirname,
const expectedFileUri = getExpectedFileUri([
"..",
"data",
"controller",
"Handler.ts"
);
"Handler.ts",
]);

// act
const result = await buildFileUri(
namespace,
Expand Down

0 comments on commit 5b190da

Please sign in to comment.