Skip to content

Commit

Permalink
fix: contextpath completion off, version template (#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
vadson71 authored Nov 21, 2023
1 parent 28a029d commit 222a0f5
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 11 deletions.
8 changes: 8 additions & 0 deletions .changeset/curly-beers-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@ui5-language-assistant/context": patch
"@ui5-language-assistant/fe": patch
"vscode-ui5-language-assistant": patch
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch
---

Code completion for context path is disabled, S/4 version placeholder in manifest's minUI5Version property defaults to the latest available version
1 change: 1 addition & 0 deletions packages/context/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { FetchResponse } from "@ui5-language-assistant/logic-utils";

export const DEFAULT_UI5_FRAMEWORK = "SAPUI5";
export const DEFAULT_UI5_VERSION = "1.71.49";
export const UI5_VERSION_S4_PLACEHOLDER = "${sap.ui5.dist.version}";
export const UI5_FRAMEWORK_CDN_BASE_URL = {
OpenUI5: "https://sdk.openui5.org/",
SAPUI5: "https://ui5.sap.com/",
Expand Down
32 changes: 22 additions & 10 deletions packages/context/src/ui5-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Json,
TypeNameFix,
} from "@ui5-language-assistant/semantic-model";
import { Fetcher } from "./types";
import { Fetcher, UI5_VERSION_S4_PLACEHOLDER } from "./types";
import { fetch } from "@ui5-language-assistant/logic-utils";
import {
getLibraryAPIJsonUrl,
Expand Down Expand Up @@ -262,12 +262,16 @@ async function getVersionInfo(
let versionInfo = await readFromCache(cacheFilePath);
if (versionInfo === undefined) {
const url = await getVersionInfoUrl(framework, version);
const response = await fetcher(url);
if (response.ok) {
versionInfo = await response.json();
writeToCache(cacheFilePath, versionInfo);
} else {
getLogger().error("Could not read version information", {
try {
const response = await fetcher(url);
if (response.ok) {
versionInfo = await response.json();
writeToCache(cacheFilePath, versionInfo);
} else {
throw new Error(`Version info request has failed (${url})`);
}
} catch (e) {
getLogger().error("Could not read version information. " + e, {
url,
});
}
Expand Down Expand Up @@ -361,11 +365,18 @@ export async function negotiateVersionWithFetcher(
// try to negotiate version
let isFallback = false;
let isIncorrectVersion = false;
let useLatestVersion = false;
let versions = versionMap[framework];

let adjustedVersion: string = version || DEFAULT_UI5_VERSION;

if (version && !isVersionSupported(version)) {
if (version === UI5_VERSION_S4_PLACEHOLDER) {
useLatestVersion = true;
adjustedVersion = version;
getLogger().warn(
`The version specified as minUI5Version in your manifest.json is not supported by Language Assistant, the latest available version is used instead`
);
} else if (version && !isVersionSupported(version)) {
// version is out of support in LA, using default version
getLogger().warn(
`The version specified as minUI5Version in your manifest.json is not supported by Language Assistant, the fallback version ${DEFAULT_UI5_VERSION} is used instead`
Expand All @@ -388,6 +399,7 @@ export async function negotiateVersionWithFetcher(
isIncorrectVersion = true;
}
} else if (
useLatestVersion ||
!(await getVersionInfo(
versionInfoJsonFetcher,
modelCachePath,
Expand Down Expand Up @@ -427,7 +439,7 @@ export async function negotiateVersionWithFetcher(
}
// coerce the version (check for invalid version, which indicates development scenario)
const parsedVersion = semver.coerce(adjustedVersion);
if (parsedVersion) {
if (!useLatestVersion && parsedVersion) {
if (versions[`${parsedVersion.major}.${parsedVersion.minor}`]) {
// lookup for a valid major.minor entry
adjustedVersion =
Expand All @@ -453,7 +465,7 @@ export async function negotiateVersionWithFetcher(
isIncorrectVersion = true;
}
} else {
// development scenario => use latest version
// development scenario or version placeholder in manifest found => use latest version
adjustedVersion = versions["latest"].version;
isIncorrectVersion = true;
}
Expand Down
18 changes: 18 additions & 0 deletions packages/context/test/unit/ui5-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe("the UI5 language assistant ui5 model", () => {
const FRAMEWORK = "SAPUI5";
const OPEN_FRAMEWORK = "OpenUI5";
const VERSION = "1.71.49";
const UI5_VERSION_S4_PLACEHOLDER = "${sap.ui5.dist.version}";
const NO_CACHE_FOLDER = undefined;

function assertSemanticModel(ui5Model: UI5SemanticModel): void {
Expand Down Expand Up @@ -623,5 +624,22 @@ describe("the UI5 language assistant ui5 model", () => {
expect(objNegotiatedVersionWithFetcher.isFallback).toBeFalse();
expect(objNegotiatedVersionWithFetcher.isIncorrectVersion).toBeTrue();
});

it("resolve unsupported version placeholder - S/4 generator artifact (should be latest)", async () => {
const objNegotiatedVersionWithFetcher = await negotiateVersionWithFetcher(
async (): Promise<FetchResponse> => {
return createResponse(true, 200, versionMap[OPEN_FRAMEWORK]);
},
async (): Promise<FetchResponse> => {
return createResponse(false, 404);
},
cachePath,
FRAMEWORK,
UI5_VERSION_S4_PLACEHOLDER
);
expect(objNegotiatedVersionWithFetcher.version).toEqual("1.105.0");
expect(objNegotiatedVersionWithFetcher.isFallback).toBeFalse();
expect(objNegotiatedVersionWithFetcher.isIncorrectVersion).toBeTrue();
});
});
});
6 changes: 6 additions & 0 deletions packages/fe/src/services/completion/providers/context-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export function contextPathSuggestions({
context.ui5Model
);

// provider is blocked and is used in tests only
// reserved for the future to be reused in binding expressions
if (!(context as unknown as { forTest: boolean }).forTest) {
return [];
}

if (
ui5Property?.library === SAP_FE_MACROS &&
ui5Property.name === "contextPath"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,28 @@ describe("contextPath attribute value completion", () => {
annoFileSegmentsCDS,
annotationSnippetCDS
);
getCompletionResult = getViewCompletionProvider(

const provider = getViewCompletionProvider(
framework,
viewFilePathSegments,
documentPath,
uri,
settings
);

getCompletionResult = (
snippet: string,
contextAdapter?: (context: Context) => Context
) => {
const testAdapter = (context: Context) => {
const result: Context = contextAdapter
? contextAdapter(context)
: context;
return { ...result, forTest: true } as Context;
};

return provider(snippet, testAdapter);
};
}, 5 * 60000);

describe("contextPath completion", () => {
Expand Down

0 comments on commit 222a0f5

Please sign in to comment.