Skip to content

Commit 6b35d43

Browse files
feat: annotation relevant lsp package (#535)
* feat: new annotation lsp package * feat: commit just to trigger rebuild * fix: yarn lock file fix * fix: yarn install fix * feat: lsp diagnostics enhancement and coverage fix * fix: coverage fix * fix: failing linter tests and other improvements * fix: diagnostics improvement, other corrections * fix: webpack bundling for module loader * feat: diagnostics improvement, partial refactoring * fix: code clean up * fix: work on pr comments * feat: i18n support * feat: manual testcases * fix: work on PR comments * fix: pr comments * fix: fe module marked as private BREAKING CHANGE: introduce context by pr #523 Co-authored-by: Klaus Keller <klaus.keller@sap.com>
1 parent 8060f6c commit 6b35d43

File tree

80 files changed

+14964
-7946
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+14964
-7946
lines changed

.vscode/launch.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@
5151
"internalConsoleOptions": "neverOpen",
5252
"disableOptimisticBPs": true,
5353
"cwd": "${workspaceFolder}/packages/context"
54+
},
55+
{
56+
"type": "node",
57+
"request": "launch",
58+
"name": "fe: run current file",
59+
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
60+
"args": ["${fileBasenameNoExtension}"],
61+
"console": "integratedTerminal",
62+
"internalConsoleOptions": "neverOpen",
63+
"disableOptimisticBPs": true,
64+
"cwd": "${workspaceFolder}/packages/fe"
65+
},
66+
{
67+
"type": "node",
68+
"request": "launch",
69+
"name": "semantic-model: run current file",
70+
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
71+
"args": ["${fileBasenameNoExtension}"],
72+
"console": "integratedTerminal",
73+
"internalConsoleOptions": "neverOpen",
74+
"disableOptimisticBPs": true,
75+
"cwd": "${workspaceFolder}/packages/semantic-model"
5476
}
5577
]
5678
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"@types/deep-equal-in-any-order": "1.0.1",
4141
"@types/fs-extra": "9.0.11",
4242
"@types/klaw-sync": "6.0.0",
43-
"@types/lodash": "4.14.168",
43+
"@types/lodash": "4.14.166",
4444
"@types/mocha": "9.1.1",
4545
"@types/rimraf": "3.0.0",
4646
"@types/sinon": "9.0.10",
@@ -58,6 +58,7 @@
5858
"fs-extra": "10.1.0",
5959
"glob": "7.1.6",
6060
"husky": "8.0.1",
61+
"i18next": "19.0.2",
6162
"klaw-sync": "6.0.0",
6263
"lerna": "6.0.3",
6364
"lint-staged": "10.5.3",

packages/context/api.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export {
1515
reactOnXmlFileChange,
1616
reactOnPackageJson,
1717
cache,
18+
DEFAULT_I18N_NAMESPACE,
1819
} from "./src/api";
1920

2021
export type {

packages/context/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"devDependencies": {
3434
"@sap-ux/vocabularies-types": "0.6.8",
3535
"@types/js-yaml": "4.0.5",
36-
"@types/lodash": "4.14.166",
36+
"@types/lodash": "4.14.168",
3737
"@types/node-fetch": "2.5.10",
3838
"@types/semver": "7.3.12",
3939
"@ui5-language-assistant/semantic-model-types": "3.3.1",

packages/context/src/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ export async function getContext(
4646
const customViewId = await getCustomViewId(documentPath);
4747
return { manifestDetails, yamlDetails, ui5Model, services, customViewId };
4848
}
49+
50+
export const DEFAULT_I18N_NAMESPACE = "translation";

packages/context/src/fetch.ts

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
1-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2-
const importDynamic = new Function("modulePath", "return import(modulePath)");
3-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4-
const nodeFetch = async (...args: any[]) => {
5-
const module = await importDynamic("node-fetch");
6-
return module.default(...args);
7-
};
8-
import { RequestInfo, RequestInit, Response } from "node-fetch";
9-
import HttpsProxyAgent from "https-proxy-agent";
101
import { getProxyForUrl } from "proxy-from-env";
2+
import HttpsProxyAgent from "https-proxy-agent";
3+
import { RequestInfo, RequestInit, Response } from "node-fetch";
4+
5+
export type FetcherType = (
6+
url: RequestInfo,
7+
init?: RequestInit | undefined
8+
) => Promise<Response>;
9+
10+
/**
11+
* Promise which prepares dynamic node fetcher function and holds it within once resolved
12+
*/
13+
const nodeFetchCached = new Promise<FetcherType>((done, reject) => {
14+
(async () => {
15+
let nodeFetch: FetcherType;
16+
try {
17+
// this should work when bundled
18+
nodeFetch = (await import("node-fetch")).default;
19+
} catch (e) {
20+
// trying to load dynamically
21+
const importDynamic = new Function(
22+
"modulePath",
23+
"return import(modulePath)"
24+
);
25+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
26+
nodeFetch = async (...args: any[]) => {
27+
const module = await importDynamic("node-fetch");
28+
return module.default(...args);
29+
};
30+
}
31+
return nodeFetch;
32+
})()
33+
.then((result) => done(result))
34+
.catch((error) => reject(error));
35+
});
1136

1237
/**
1338
* Wrapper for the node-fetch API to utilize a proxy if needed
@@ -28,6 +53,8 @@ export default async function fetch(
2853
agent: HttpsProxyAgent(proxy),
2954
});
3055
}
31-
// call the node-fetch API
56+
57+
// call the cached node-fetch API
58+
const nodeFetch = await nodeFetchCached;
3259
return nodeFetch(url, init);
3360
}

packages/fe/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

packages/fe/CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Contribution Guide
2+
3+
This package does not have any unique development flows.
4+
Please see the top level [Contribution Guide](../../CONTRIBUTING.md).

packages/fe/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[![npm (scoped)](https://img.shields.io/npm/v/@ui5-language-assistant/context.svg)](https://www.npmjs.com/package/@ui5-language-assistant/fe)
2+
3+
# @ui5-language-assistant/fe
4+
5+
UI5 language assistant extension with LSP for annotation-relevant building blocks
6+
7+
## Installation
8+
9+
With npm:
10+
11+
- `npm install @ui5-language-assistant/fe`
12+
13+
With Yarn:
14+
15+
- `yarn add @ui5-language-assistant/fe`
16+
17+
## Usage
18+
19+
This package only exposes programmatic APIs, import the package and use the exported APIs
20+
defined in [api.d.ts](./api.d.ts).
21+
22+
## Support
23+
24+
Please open [issues](https://github.com/SAP/ui5-language-assistant/issues) on github.
25+
26+
## Contributing
27+
28+
See [CONTRIBUTING.md](./CONTRIBUTING.md).
29+
30+
## Licensing
31+
32+
Copyright 2022 SAP SE. Please see our [LICENSE](../../LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/SAP/ui5-language-assistant).

packages/fe/api.d.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type {
2+
BaseUI5XMLViewIssue,
3+
UI5ValidatorsConfig,
4+
} from "@ui5-language-assistant/xml-views-validation";
5+
import type { Context } from "@ui5-language-assistant/context";
6+
import type {
7+
TextDocumentPositionParams,
8+
CompletionItem,
9+
} from "vscode-languageserver-protocol";
10+
import type { CstNode, IToken } from "chevrotain";
11+
import type { XMLDocument } from "@xml-tools/ast";
12+
import type { TextDocument } from "vscode-languageserver-textdocument";
13+
import type { Settings } from "@ui5-language-assistant/settings";
14+
import type { AnnotationIssue } from "./src/types/issues";
15+
16+
export type { AnnotationIssue } from "./src/types/issues";
17+
18+
export declare const defaultValidators: UI5ValidatorsConfig<AnnotationIssue>;
19+
20+
export function getCompletionItems(opts: {
21+
context: Context;
22+
textDocumentPosition: TextDocumentPositionParams;
23+
document: TextDocument;
24+
documentSettings: Settings;
25+
cst: CstNode;
26+
tokenVector: IToken[];
27+
ast: XMLDocument;
28+
}): CompletionItem[];
29+
30+
export function isAnnotationIssue<T extends BaseUI5XMLViewIssue>(
31+
issue: AnnotationIssue | T
32+
): issue is AnnotationIssue;
33+
34+
export function initI18n(i18nInstance: i18n): void;

0 commit comments

Comments
 (0)