Skip to content

Commit cf2e63b

Browse files
authored
feat: make vscode extension work (with known issues with goto-definition) (#19)
- bundling and packaging vscode extension - more validation tests
1 parent d83a641 commit cf2e63b

29 files changed

+8745
-7835
lines changed

packages/schema/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/out/
22
/tests/coverage/
3+
/bundle
4+
*.vsix

packages/schema/.vscodeignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
.vscode/**
22
.vscode-test/**
33
.gitignore
4-
langium-quickstart.md
4+
src
5+
tests
6+
node_modules
7+
bin
8+
build
9+
jest.config.ts
10+
tsconfig.json

packages/schema/LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2022 ZenStack Language Tools
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

packages/schema/bin/cli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env node
22

3-
require("../out/cli").default();
3+
require('../bundle/cli').default();

packages/schema/langium-quickstart.md

Lines changed: 0 additions & 41 deletions
This file was deleted.

packages/schema/package.json

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
{
22
"name": "zenstack",
3-
"displayName": "ZenStack CLI and Language Tools",
4-
"description": "ZenStack CLI and Language Tools",
5-
"version": "0.1.47",
3+
"publisher": "zenstack",
4+
"displayName": "ZenStack Language Tools",
5+
"description": "ZenStack is a toolkit that simplifies full-stack development",
6+
"version": "0.1.49",
7+
"author": {
8+
"name": "ymc9"
9+
},
10+
"keywords": [
11+
"fullstack",
12+
"react",
13+
"typescript",
14+
"data modeling"
15+
],
16+
"preview": true,
17+
"icon": "asset/logo-light.png",
18+
"repository": {
19+
"type": "git",
20+
"url": "https://github.com/zenstackhq/zenstack"
21+
},
622
"engines": {
7-
"vscode": "^1.56.0"
23+
"vscode": "^1.72.0"
824
},
925
"categories": [
1026
"Programming Languages"
@@ -40,23 +56,27 @@
4056
],
4157
"files": [
4258
"bin",
43-
"out"
59+
"src",
60+
"bundle"
4461
],
4562
"bin": {
4663
"zenstack": "./bin/cli"
4764
},
48-
"main": "./out/extension.js",
65+
"main": "./bundle/extension.js",
4966
"scripts": {
50-
"vscode:prepublish": "npm run build && npm run lint",
51-
"build": "npm run langium:generate && tsc && tsc-alias && cp src/language-server/stdlib.zmodel ./out/language-server/ && cp src/generator/*.template.json ./out/generator/",
52-
"ts:watch": "tsc --watch",
67+
"vscode:publish": "vsce publish --no-dependencies",
68+
"vscode:prepublish": "pnpm lint && pnpm build && pnpm bundle",
69+
"vscode:package": "vsce package --no-dependencies",
70+
"build": "pnpm langium:generate && tsc --noEmit",
71+
"bundle": "node build/bundle.js",
72+
"ts:watch": "tsc --watch --noEmit",
5373
"tsc-alias:watch": "tsc-alias --watch",
5474
"lint": "eslint src --ext ts",
5575
"langium:generate": "langium generate",
5676
"langium:watch": "langium generate --watch",
5777
"watch": "concurrently --kill-others \"npm:langium:watch\" \"npm:ts:watch\" \"npm:tsc-alias:watch\"",
5878
"test": "jest",
59-
"prepublishOnly": "pnpm build"
79+
"prepublishOnly": "pnpm build && pnpm bundle"
6080
},
6181
"dependencies": {
6282
"@zenstackhq/internal": "workspace:*",
@@ -73,6 +93,7 @@
7393
"vscode-jsonrpc": "^8.0.2",
7494
"vscode-languageclient": "^8.0.2",
7595
"vscode-languageserver": "^8.0.2",
96+
"vscode-languageserver-textdocument": "^1.0.7",
7697
"vscode-uri": "^3.0.6"
7798
},
7899
"devDependencies": {
@@ -86,6 +107,7 @@
86107
"@typescript-eslint/eslint-plugin": "^4.33.0",
87108
"@typescript-eslint/parser": "^4.33.0",
88109
"concurrently": "^7.4.0",
110+
"esbuild": "^0.15.12",
89111
"eslint": "^7.32.0",
90112
"jest": "^29.2.1",
91113
"langium-cli": "^0.5.0",
@@ -94,6 +116,7 @@
94116
"ts-node": "^10.9.1",
95117
"tsc-alias": "^1.7.0",
96118
"tsconfig-paths-jest": "^0.0.1",
97-
"typescript": "^4.8.4"
119+
"typescript": "^4.8.4",
120+
"vsce": "^2.13.0"
98121
}
99122
}

packages/schema/src/cli/cli-util.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'path';
33
import fs from 'fs';
44
import { AstNode, LangiumDocument, LangiumServices } from 'langium';
55
import { URI } from 'vscode-uri';
6+
import { STD_LIB_MODULE_NAME } from '@lang/constants';
67

78
export async function extractDocument(
89
fileName: string,
@@ -23,8 +24,13 @@ export async function extractDocument(
2324

2425
const stdLib =
2526
services.shared.workspace.LangiumDocuments.getOrCreateDocument(
26-
URI.file(path.join(__dirname, '../language-server/stdlib.zmodel'))
27+
URI.file(
28+
path.resolve(
29+
path.join(__dirname, '../res', STD_LIB_MODULE_NAME)
30+
)
31+
)
2732
);
33+
2834
const document =
2935
services.shared.workspace.LangiumDocuments.getOrCreateDocument(
3036
URI.file(path.resolve(fileName))

packages/schema/src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function deactivate(): Thenable<void> | undefined {
2424

2525
function startLanguageClient(context: vscode.ExtensionContext): LanguageClient {
2626
const serverModule = context.asAbsolutePath(
27-
path.join('out', 'language-server', 'main')
27+
path.join('bundle', 'language-server', 'main')
2828
);
2929
// The debug options for the server
3030
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging.

packages/schema/src/generator/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class ZenStackGenerator {
5151
// generate package.json
5252
const packageJson = require(path.join(
5353
__dirname,
54+
'../res',
5455
'package.template.json'
5556
));
5657
fs.writeFileSync(
@@ -61,6 +62,7 @@ export class ZenStackGenerator {
6162
// compile ts sources
6263
const tsConfig = require(path.join(
6364
__dirname,
65+
'../res',
6466
'tsconfig.template.json'
6567
));
6668
fs.writeFileSync(

packages/schema/src/language-server/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ export const SCALAR_TYPES = [
1515
'Bytes',
1616
'DateTime',
1717
];
18+
19+
export const STD_LIB_MODULE_NAME = 'stdlib.zmodel';

0 commit comments

Comments
 (0)