Skip to content

Commit ce59328

Browse files
authored
feat: introduce context package (#523)
* feat: introduce context package * fix: react on file changes * fix: address review comments * fix: replace console with logger * fix: use logger per package * fix: add unit test for test framework * fix: address review comments * fix: react to package.json file and small enhancement * fix: correct custom views * fix: ci issue * fix: review comments * fix: review comment * fix: remove project contents * fix: remove project contents except `node_modules` and `package-lock.json` * fix: docker image
1 parent 18c15ff commit ce59328

File tree

186 files changed

+29739
-3203
lines changed

Some content is hidden

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

186 files changed

+29739
-3203
lines changed

.vscode/launch.json

+11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@
4040
"port": 6009,
4141
"restart": true,
4242
"outFiles": ["${workspaceRoot}/packages/language-server/lib/src/**/*.js"]
43+
},
44+
{
45+
"type": "node",
46+
"request": "launch",
47+
"name": "context: run current file",
48+
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
49+
"args": ["${fileBasenameNoExtension}"],
50+
"console": "integratedTerminal",
51+
"internalConsoleOptions": "neverOpen",
52+
"disableOptimisticBPs": true,
53+
"cwd": "${workspaceFolder}/packages/context"
4354
}
4455
]
4556
}

packages/context/CHANGELOG.md

+4
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/context/CONTRIBUTING.md

+4
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/context/README.md

+32
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/context)
2+
3+
# @ui5-language-assistant/context
4+
5+
A context for a workspace containing one or more projects. Other packages in this mono repo can consume this context to implement editor functionality such as content-assist or validations.
6+
7+
## Installation
8+
9+
With npm:
10+
11+
- `npm install @ui5-language-assistant/context`
12+
13+
With Yarn:
14+
15+
- `yarn add @ui5-language-assistant/context`
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/context/api.d.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export {
2+
getContext,
3+
getCDNBaseUrl,
4+
initializeManifestData,
5+
initializeUI5YamlData,
6+
findManifestPath,
7+
findYamlPath,
8+
getManifestDetails,
9+
getUI5Manifest,
10+
getUI5Yaml,
11+
getYamlDetails,
12+
reactOnCdsFileChange,
13+
reactOnUI5YamlChange,
14+
reactOnManifestChange,
15+
reactOnXmlFileChange,
16+
reactOnPackageJson,
17+
cache,
18+
} from "./src/api";
19+
20+
export type {
21+
Context,
22+
ManifestDetails,
23+
YamlDetails,
24+
ProjectKind,
25+
} from "./src/types";
26+
export type { Manifest } from "@sap-ux/project-access";

packages/context/nyc.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const baseConfig = require("../nyc.config");
2+
module.exports = {
3+
...baseConfig,
4+
include: ["lib/**/*.js"],
5+
};

packages/context/package.json

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "@ui5-language-assistant/context",
3+
"version": "3.3.1",
4+
"description": "A context for an xml file",
5+
"keywords": [],
6+
"files": [
7+
".reuse",
8+
"LICENSES",
9+
"lib/src",
10+
"api.d.ts",
11+
"src"
12+
],
13+
"main": "lib/src/api.js",
14+
"repository": "https://github.com/sap/ui5-language-assistant/",
15+
"license": "Apache-2.0",
16+
"typings": "./api.d.ts",
17+
"dependencies": {
18+
"@ui5-language-assistant/logic-utils": "3.3.1",
19+
"@sap-ux/project-access": "1.0.2",
20+
"lodash": "4.17.21",
21+
"fs-extra": "10.1.0",
22+
"vscode-uri": "2.1.2",
23+
"vscode-languageserver": "8.0.2",
24+
"globby": "11.1.0",
25+
"js-yaml": "4.1.0",
26+
"https-proxy-agent": "5.0.1",
27+
"proxy-from-env": "1.1.0",
28+
"node-fetch": "3.2.10",
29+
"semver": "7.3.7",
30+
"@sap-ux/annotation-converter": "0.5.20",
31+
"@sap-ux/edmx-parser": "0.5.13"
32+
},
33+
"devDependencies": {
34+
"@sap-ux/vocabularies-types": "0.6.8",
35+
"@types/js-yaml": "4.0.5",
36+
"@types/lodash": "4.14.166",
37+
"@types/node-fetch": "2.5.10",
38+
"@types/semver": "7.3.12",
39+
"@ui5-language-assistant/semantic-model-types": "3.3.1",
40+
"@ui5-language-assistant/test-utils": "3.3.1",
41+
"@ui5-language-assistant/test-framework": "3.3.1",
42+
"tmp-promise": "3.0.2",
43+
"rimraf": "3.0.2"
44+
},
45+
"scripts": {
46+
"ci": "npm-run-all clean compile lint coverage",
47+
"clean": "rimraf ./lib ./coverage ./nyc_output",
48+
"compile": "yarn run clean && tsc -p .",
49+
"compile:watch": "tsc -p . --watch",
50+
"lint": "eslint . --ext .ts --max-warnings=0 --ignore-path=../../.gitignore",
51+
"test": "mocha",
52+
"coverage": "nyc mocha"
53+
},
54+
"publishConfig": {
55+
"access": "public"
56+
}
57+
}

packages/context/src/api.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { getCustomViewId, getManifestDetails } from "./manifest";
2+
import { getServices } from "./services";
3+
import { Context } from "./types";
4+
import { getSemanticModel } from "./ui5-model";
5+
import { getYamlDetails } from "./ui5-yaml";
6+
7+
export {
8+
initializeManifestData,
9+
getManifestDetails,
10+
getUI5Manifest,
11+
findManifestPath,
12+
} from "./manifest";
13+
export {
14+
initializeUI5YamlData,
15+
getYamlDetails,
16+
getUI5Yaml,
17+
findYamlPath,
18+
} from "./ui5-yaml";
19+
export { getCDNBaseUrl } from "./utils";
20+
export { cache } from "./cache";
21+
export {
22+
reactOnCdsFileChange,
23+
reactOnUI5YamlChange,
24+
reactOnManifestChange,
25+
reactOnXmlFileChange,
26+
reactOnPackageJson,
27+
} from "./watcher";
28+
29+
/**
30+
* Get context for a file
31+
* @param documentPath path to a file e.g. absolute/path/webapp/ext/main/Main.view.xml
32+
* @param modelCachePath path to a cached UI5 model
33+
*/
34+
export async function getContext(
35+
documentPath: string,
36+
modelCachePath?: string
37+
): Promise<Context> {
38+
const manifestDetails = await getManifestDetails(documentPath);
39+
const yamlDetails = await getYamlDetails(documentPath);
40+
const ui5Model = await getSemanticModel(
41+
modelCachePath,
42+
yamlDetails.framework,
43+
manifestDetails.minUI5Version
44+
);
45+
const services = await getServices(documentPath);
46+
const customViewId = await getCustomViewId(documentPath);
47+
return { manifestDetails, yamlDetails, ui5Model, services, customViewId };
48+
}

packages/context/src/cache.ts

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import type { Manifest } from "@sap-ux/project-access";
2+
import type { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types";
3+
4+
import type { App, Project, YamlDetails } from "./types";
5+
6+
type AbsoluteAppRoot = string;
7+
type AbsoluteProjectRoot = string;
8+
9+
class Cache {
10+
private manifest: Map<AbsoluteAppRoot, Manifest>;
11+
private app: Map<AbsoluteAppRoot, App>;
12+
private project: Map<AbsoluteAppRoot, Project>;
13+
private CAPServices: Map<AbsoluteProjectRoot, Map<string, string>>;
14+
private ui5YamlDetails: Map<string, YamlDetails>;
15+
private ui5Model: Map<string, UI5SemanticModel>;
16+
constructor() {
17+
this.project = new Map();
18+
this.manifest = new Map();
19+
this.app = new Map();
20+
this.CAPServices = new Map();
21+
this.ui5YamlDetails = new Map();
22+
this.ui5Model = new Map();
23+
}
24+
reset() {
25+
this.project = new Map();
26+
this.manifest = new Map();
27+
this.app = new Map();
28+
this.CAPServices = new Map();
29+
this.ui5YamlDetails = new Map();
30+
this.ui5Model = new Map();
31+
}
32+
/**
33+
* Get entries of cached project
34+
*/
35+
getProjectEntries(): string[] {
36+
return [...this.project.keys()];
37+
}
38+
getProject(projectRoot: AbsoluteProjectRoot): Project | undefined {
39+
return this.project.get(projectRoot);
40+
}
41+
setProject(projectRoot: AbsoluteProjectRoot, data: Project): void {
42+
this.project.set(projectRoot, data);
43+
}
44+
deleteProject(projectRoot: AbsoluteProjectRoot): boolean {
45+
return this.project.delete(projectRoot);
46+
}
47+
/**
48+
* Get entries of cached manifest
49+
*/
50+
getManifestEntries(): string[] {
51+
return [...this.manifest.keys()];
52+
}
53+
getManifest(manifestRoot: string): Manifest | undefined {
54+
return this.manifest.get(manifestRoot);
55+
}
56+
setManifest(manifestRoot: string, data: Manifest): void {
57+
this.manifest.set(manifestRoot, data);
58+
}
59+
deleteManifest(manifestRoot: string): boolean {
60+
return this.manifest.delete(manifestRoot);
61+
}
62+
/**
63+
* Get entries of cached app
64+
*/
65+
getAppEntries(): string[] {
66+
return [...this.app.keys()];
67+
}
68+
getApp(appRoot: string): App | undefined {
69+
return this.app.get(appRoot);
70+
}
71+
setApp(appRoot: string, data: App): void {
72+
this.app.set(appRoot, data);
73+
}
74+
deleteApp(appRoot: string): boolean {
75+
return this.app.delete(appRoot);
76+
}
77+
/**
78+
* Get entries of cached CAP services
79+
*/
80+
getCAPServiceEntries(): string[] {
81+
return [...this.CAPServices.keys()];
82+
}
83+
getCAPServices(
84+
projectRoot: AbsoluteProjectRoot
85+
): Map<string, string> | undefined {
86+
return this.CAPServices.get(projectRoot);
87+
}
88+
setCAPServices(
89+
projectRoot: AbsoluteProjectRoot,
90+
data: Map<string, string>
91+
): void {
92+
this.CAPServices.set(projectRoot, data);
93+
}
94+
deleteCAPServices(projectRoot: AbsoluteProjectRoot): boolean {
95+
return this.CAPServices.delete(projectRoot);
96+
}
97+
/**
98+
* Get entries of cached yaml details
99+
*/
100+
getYamlDetailsEntries(): string[] {
101+
return [...this.ui5YamlDetails.keys()];
102+
}
103+
getYamlDetails(documentPath: string): YamlDetails | undefined {
104+
return this.ui5YamlDetails.get(documentPath);
105+
}
106+
setYamlDetails(documentPath: string, data: YamlDetails): void {
107+
this.ui5YamlDetails.set(documentPath, data);
108+
}
109+
deleteYamlDetails(documentPath: string): boolean {
110+
return this.ui5YamlDetails.delete(documentPath);
111+
}
112+
/**
113+
* Get entries of cached UI5 model
114+
*/
115+
getUI5ModelEntries(): string[] {
116+
return [...this.ui5Model.keys()];
117+
}
118+
getUI5Model(key: string): UI5SemanticModel | undefined {
119+
return this.ui5Model.get(key);
120+
}
121+
setUI5Model(key: string, data: UI5SemanticModel): void {
122+
this.ui5Model.set(key, data);
123+
}
124+
deleteUI5Model(key: string): boolean {
125+
return this.ui5Model.delete(key);
126+
}
127+
}
128+
129+
/**
130+
* Create singleton instance of Cache
131+
*/
132+
const cache = new Cache();
133+
export { cache };
File renamed without changes.

0 commit comments

Comments
 (0)