Skip to content

Commit

Permalink
Bundle with esbuild (#4)
Browse files Browse the repository at this point in the history
- Bundle compiled server and client modules, including tree-sitter wasm files.
  • Loading branch information
AnHeuermann authored Jan 31, 2024
1 parent 79ad2b2 commit 5424e7a
Show file tree
Hide file tree
Showing 15 changed files with 502 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: npm clean-install && npm run postinstall

- name: Build package
run: npm run compile
run: npm run esbuild

- name: Test language server
run: npm run test:server
Expand Down
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.vscode-test
client/server
modelica-language-server*.vsix
node_modules
out
node_modules/
out/
12 changes: 8 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
"version": "0.2.0",
"configurations": [
{
"name": "Launch Client",
"type": "extensionHost",
"request": "launch",
"name": "Launch Client",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}"
],
"outFiles": [
"${workspaceRoot}/client/out/**/*.js"
"${workspaceRoot}/out/**/*.js"
],
"preLaunchTask": {
"type": "npm",
"script": "watch"
"script": "esbuild-watch"
}
},
{
Expand All @@ -31,7 +31,11 @@
],
"outFiles": [
"${workspaceRoot}/client/out/test/**/*.js"
]
],
"preLaunchTask": {
"type": "npm",
"script": "test-compile"
}
}
]
}
23 changes: 12 additions & 11 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
!server/OSMC-License.txt
.eslintignore
.github
.gitignore
.travis.yml
.vscode/**
**/*.ts
**/*.map
.gitignore
**/tsconfig.json
**/*.ts
**/tsconfig.base.json
**/tsconfig.json
client/
contributing.md
.travis.yml
client/node_modules/**
!client/node_modules/vscode-jsonrpc/**
!client/node_modules/vscode-languageclient/**
!client/node_modules/vscode-languageserver-protocol/**
!client/node_modules/vscode-languageserver-types/**
!client/node_modules/{minimatch,brace-expansion,concat-map,balanced-match}/**
!client/node_modules/{semver,lru-cache,yallist}/**
esbuild.config.js
node_modules/
scripts/
server/
File renamed without changes.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Check the Marketplace for

## Building the Language Server

- Run `npm install` in this folder. This installs all necessary npm modules in
both the client and server folder
- Run `npm install` and `npm run postinstall` in this folder.This installs all
necessary npm modules in both the client and server folder
- Open VS Code on this folder.
- Press Ctrl+Shift+B to start compiling the client and server in [watch
mode](https://code.visualstudio.com/docs/editor/tasks#:~:text=The%20first%20entry%20executes,the%20HelloWorld.js%20file.).
Expand All @@ -59,10 +59,8 @@ npx vsce package

## License

Copyright (C) 2023-2024 Andreas Heuermann, Osman Karabel

modelica-language-server is licensed under the
GNU Affero General Public License v3, see [COPYING.md](./COPYING.md).
GNU Affero General Public License v3, see [LICENSE.md](./LICENSE.md).

### 3rd Party Licenses

Expand All @@ -71,8 +69,8 @@ This extension is based on
licensed under MIT license.

Some parts of the source code are taken from
[bash-language-server](https://github.com/bash-lsp/bash-language-server),
licensed under the MIT license, and adapted to the Modelica language server.
[bash-lsp/bash-language-server](https://github.com/bash-lsp/bash-language-server),
licensed under the MIT license and adapted to the Modelica language server.

[OpenModelica/tree-sitter-modelica](https://github.com/OpenModelica/tree-sitter-modelica)
v0.2.0 is included in this extension and is licensed under the [OSMC-PL
Expand Down
9 changes: 7 additions & 2 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import * as path from 'path';
import * as fs from 'fs';
import { languages, workspace, ExtensionContext, TextDocument } from 'vscode';
import {
LanguageClient,
Expand All @@ -25,6 +26,7 @@ import {
TransportKind
} from 'vscode-languageclient/node';
import { getFileExtension, getLanguage } from './getLanguage';
import { fstat } from 'fs';

let client: LanguageClient;

Expand Down Expand Up @@ -53,10 +55,13 @@ export function activate(context: ExtensionContext) {
}
});

// The server is implemented in node
// The server is implemented in node, point to packed module
const serverModule = context.asAbsolutePath(
path.join('server', 'out', 'server.js')
path.join('out', 'server.js')
);
if (!fs.existsSync(serverModule)) {
throw new Error(`Can't find server module in ${serverModule}`);
}

// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
Expand Down
2 changes: 1 addition & 1 deletion client/src/test/symbolinformation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ function assertDocumentSymbolsEqual(expected: vscode.DocumentSymbol[], actual: v
// Recursive check for children symbols
assertDocumentSymbolsEqual(expectedSymbol.children || [], actualSymbol.children || []);
}
}
}
39 changes: 39 additions & 0 deletions esbuild.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const esbuild = require('esbuild');
const fs = require('fs');

// Build client
esbuild.build({
entryPoints: [
'./client/src/extension.ts'
],
bundle: true,
outfile: './out/client.js',
platform: 'node',
external: [
'vscode'
],
format: 'cjs',
tsconfig: './client/tsconfig.json',
}).catch(() => process.exit(1));

// Build server
esbuild.build({
entryPoints: [
'./server/src/server.ts'
],
bundle: true,
outfile: './out/server.js',
platform: 'node',
external: [
'vscode',
],
format: 'cjs',
tsconfig: './server/tsconfig.json',
}).catch(() => process.exit(1));

// Copy tree-sitter.wasm and tree-sitter-modelica.wasm to the output directory
if (!fs.existsSync('out')) {
fs.mkdirSync('out');
}
fs.copyFileSync('./server/src/tree-sitter-modelica.wasm', './out/tree-sitter-modelica.wasm');
fs.copyFileSync('./server/node_modules/web-tree-sitter/tree-sitter.wasm', './out/tree-sitter.wasm');
Loading

0 comments on commit 5424e7a

Please sign in to comment.