Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add web extension support for syntax highlighting #2323

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5a5abc0
Add web extension support for syntax highlighting
mm-broadcom May 31, 2024
6027c31
Limit commands in web context
mm-broadcom Jun 3, 2024
f606e48
Update web extension output directory
mm-broadcom Jun 4, 2024
97bdfbb
Update Build.sh to build web extension
mm-broadcom Jun 4, 2024
035a21b
Change Web build command to "browser" as platform
mm-broadcom Jun 5, 2024
878ef80
Update packaage.json to change "when" clauses
mm-broadcom Jun 5, 2024
b5ffdca
Add package command for web extension
mm-broadcom Jun 5, 2024
5a56dd0
Replace webpack with esbuild
mm-broadcom Jun 7, 2024
97c39a4
Add web build to build.yml
mm-broadcom Jun 7, 2024
c20d318
Remove unused Webpack-related packages
mm-broadcom Jun 10, 2024
5d2ef40
Add package:web step to Github workflow
mm-broadcom Jun 10, 2024
53df542
Update package-lock.json
mm-broadcom Jun 10, 2024
0b1a714
Revert "Update package-lock.json"
mm-broadcom Jun 10, 2024
65dda45
Updated package-lock.json
mm-broadcom Jun 10, 2024
bb38cc0
Fix assert build issues
mm-broadcom Jun 11, 2024
b1581d0
Remove Node Polyfill
mm-broadcom Jun 11, 2024
b0754fe
Make buildWeb a separate job step for CI
mm-broadcom Jun 11, 2024
65e4e80
Ran Prettier
mm-broadcom Jun 11, 2024
202ec87
Add upload step to buildWeb job
mm-broadcom Jun 11, 2024
8130852
Update .github/workflows/build.yml
mm-broadcom Jun 11, 2024
c39993b
TDD fixes for web extension
mm-broadcom Jun 11, 2024
78062a4
Merge branch 'web-extension-support' of https://github.com/mm-broadco…
mm-broadcom Jun 11, 2024
270363f
Rename esbuild.js
mm-broadcom Jun 11, 2024
9831f12
Update .vscodeignore
mm-broadcom Jun 11, 2024
3801e9a
Fix web build and package
mm-broadcom Jun 12, 2024
3c8898b
Add production flag to web build in prepackage
mm-broadcom Jun 12, 2024
440ddd9
Update .vscodeignore
mm-broadcom Jun 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ jobs:
run: |
npm ci
npm run test
- name: Unit Test COBOL LS Web extension
working-directory: clients/cobol-lsp-vscode-extension
run: |
npm ci
npm run test:web
- name: Package IDMS vsix
working-directory: clients/idms-dialect-support
run: |
Expand Down Expand Up @@ -341,6 +346,11 @@ jobs:
run: |
npm run package -- --target ${{ env.target }}
cp *.vsix ../../.
- name: Package COBOL LS vsix for Web
working-directory: clients/cobol-lsp-vscode-extension
run: |
npm run package:web
cp *.vsix ../../.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will run 6x (once in each native configuration) and possibly overwrite the "desktop" VSIX package.
I suggest creating a separate job (e.g. buildWeb) in this file that will just do

  • checkout
  • "update version for PR" step
  • npm ci
  • npm run test:web
  • npm run package:web
  • upload artifact to preserve the VSIX

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes a separate vsix file with the name cobol-language-support-web-[version] where version is the latest numbered version. (2.1.2 as of this writing.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a separate job for building the web extension. Will need some help with the upload as there isn't an existing one to handle the artifact.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- uses: actions/upload-artifact@v3
with:
if-no-files-found: warn
name: vsix-cobol-language-support-${{ env.target }}
path: 'cobol-language-support*.vsix'

- uses: actions/upload-artifact@v3
with:
if-no-files-found: warn
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ local.properties
out
*.vsix
.vscode-test
.vscode-test-web
node_modules
tools
logs/app.log
Expand Down
6 changes: 6 additions & 0 deletions BUILD.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,11 @@ npm ci
npm run package
cd -

# Build COBOL LS Web extension
cd clients/cobol-lsp-vscode-extension
npm ci
npm run build:web
cd -

# Done
echo "Done building COBOL LS"
2 changes: 2 additions & 0 deletions clients/cobol-lsp-vscode-extension/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
# * bundled extension code
!dist/extension.js
!dist/extension.js.map
!dist/web/extension.js
!dist/web/extension.js.map
# ** server implementation
!server/native/*
!server/jar/server.jar
Expand Down
100 changes: 100 additions & 0 deletions clients/cobol-lsp-vscode-extension/esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
const esbuild = require('esbuild');
const glob = require('glob');
const path = require('path');
const polyfill = require('@esbuild-plugins/node-globals-polyfill');

const production = process.argv.includes('--production');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that the argument is actually provided in the build scripts.

const watch = process.argv.includes('--watch');

/**
* This plugin hooks into the build process to print errors in a format that the problem matcher in
* Visual Studio Code can understand.
* @type {import('esbuild').Plugin}
*/
const esbuildProblemMatcherPlugin = {
name: 'esbuild-problem-matcher',

setup(build) {
build.onStart(() => {
console.log('[watch] build started');
});
build.onEnd((result) => {
result.errors.forEach(({ text, location }) => {
console.error(`✘ [ERROR] ${text}`);
console.error(` ${location.file}:${location.line}:${location.column}:`);
});
console.log('[watch] build finished');
});
},
};


/**
* For web extension, all tests, including the test runner, need to be bundled into
* a single module that has a exported `run` function .
* This plugin bundles implements a virtual file extensionTests.ts that bundles all these together.
* @type {import('esbuild').Plugin}
*/
const testBundlePlugin = {
name: 'testBundlePlugin',
setup(build) {
build.onResolve({ filter: /[\/\\]extensionTests\.ts$/ }, args => {
if (args.kind === 'entry-point') {
return { path: path.resolve(args.path) };
}
});
build.onLoad({ filter: /[\/\\]extensionTests\.ts$/ }, async args => {
const testsRoot = path.join(__dirname, 'src/web/test/suite');
const files = await glob.glob('*.test.{ts,tsx}', { cwd: testsRoot, posix: true });
return {
contents:
`export { run } from './mochaTestRunner.ts';` +
files.map(f => `import('./${f}');`).join(''),
watchDirs: files.map(f => path.dirname(path.resolve(testsRoot, f))),
watchFiles: files.map(f => path.resolve(testsRoot, f))
};
});
}
};

async function main() {
const ctx = await esbuild.context({
entryPoints: [
'src/web/extension.ts',
'src/web/test/suite/extensionTests.ts'
],
bundle: true,
format: 'cjs',
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: 'browser',
outdir: 'dist/web',
external: ['vscode'],
logLevel: 'silent',
// Node.js global to browser globalThis
define: {
global: 'globalThis',
},

plugins: [
mm-broadcom marked this conversation as resolved.
Show resolved Hide resolved
polyfill.NodeGlobalsPolyfillPlugin({
process: true,
buffer: true,
}),
mm-broadcom marked this conversation as resolved.
Show resolved Hide resolved
testBundlePlugin,
esbuildProblemMatcherPlugin, /* add to the end of plugins array */
],
});
if (watch) {
await ctx.watch();
} else {
await ctx.rebuild();
await ctx.dispose();
}
}

main().catch(e => {
console.error(e);
process.exit(1);
});
Loading
Loading