Skip to content

Commit

Permalink
Fix ups for debugging flow
Browse files Browse the repository at this point in the history
  • Loading branch information
cwahbong committed Oct 25, 2024
1 parent 1cb2804 commit d685dbb
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 39 deletions.
15 changes: 8 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,29 @@
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"stopOnEntry": false,
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/src/**/*.js"],
"preLaunchTask": "npm"
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"preLaunchTask": "npm: compile"
},
{
"name": "Launch Debug Server",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/src/debug-adapter/client.ts",
"program": "${workspaceFolder}/dist/debug-adapter-client.js",
"args": ["--server=4711"],
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/src/**/*.js"]
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
},
{
"name": "Launch Extension Tests",
"type": "extensionHost",
"request": "launch",
"testConfiguration": "${workspaceFolder}/.vscode-test.js",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"]
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/out/**/*.js"]
}
],
"compounds": [
Expand Down
10 changes: 10 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Ignore all files by default.
**/*

!README.md
!LICENSE
!package.json
!dist/**/*.js
!icons/**/*.+(svg|license)
!media/**/*
!syntaxes/**/*.+(json|yaml|license)
56 changes: 56 additions & 0 deletions esbuild-debug-adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const esbuild = require("esbuild");

const production = process.argv.includes("--production");
const watch = process.argv.includes("--watch");

/**
* @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");
});
},
};

async function main() {
const ctx = await esbuild.context({
entryPoints: ["src/debug-adapter/client.ts"],
bundle: true,
format: "cjs",
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: "node",
outfile: "dist/debug-adapter-client.js",
external: ["vscode"],
logLevel: "silent",
plugins: [
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
],
});
if (watch) {
await ctx.watch();
} else {
await ctx.rebuild();
await ctx.dispose();
}
}

main().catch((e) => {
console.error(e);
process.exit(1);
});
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = tseslint.config(
eslintConfigPrettier,
{
ignores: [
"esbuild.js",
"esbuild*.js",
"dist/",
"out/",
"src/protos/protos.js",
"src/protos/protos.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"onCommand:bazel.info.output_path",
"onCommand:bazel.info.workspace"
],
"main": "./extension.js",
"main": "./dist/extension.js",
"contributes": {
"breakpoints": [
{
Expand Down Expand Up @@ -200,7 +200,7 @@
{
"type": "bazel-launch-build",
"label": "Launch Bazel Build",
"program": "./out/src/debug-adapter/client.js",
"program": "./dist/debug-adapter-client.js",
"runtime": "node",
"configurationAttributes": {
"launch": {
Expand Down Expand Up @@ -467,7 +467,7 @@
"test": "./scripts/test.sh",
"package": "./scripts/package.sh",
"update-snapshot": "./scripts/test.sh -u",
"watch": "./scripts/build.sh -watch"
"watch": "./scripts/build.sh --watch"
},
"devDependencies": {
"@types/mocha": "^10.0.6",
Expand Down
18 changes: 5 additions & 13 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,12 @@ set -eu
# Move into the top-level directory of the project.
cd "$(dirname "${BASH_SOURCE[0]}")/.." > /dev/null

# Only regenerate the .js and .t.ds file if the protos have changed (i.e.,
# it's a fresh checkout or update_protos.sh has been executed again and
# deleted the old generated files). This shaves several seconds off the
# extension's build time.
if [[ ! -f src/protos/protos.js ]] ; then
sed -e "s#^#src/protos/#" src/protos/protos_list.txt | \
xargs pbjs -t static-module -o src/protos/protos.js
fi
if [[ ! -f src/protos/protos.d.ts ]] ; then
pbts -o src/protos/protos.d.ts src/protos/protos.js
fi
./scripts/prepare.sh

# Convert yaml language definition to json form requred by vscode.
js-yaml syntaxes/bazelrc.tmLanguage.yaml > syntaxes/bazelrc.tmLanguage.json
# Do not watch. Drop minify as well before we have a better arg parse here.
node esbuild-debug-adapter.js

node esbuild.js

# Compile the rest of the project for non-release development flow.
tsc "$@" -p ./
17 changes: 5 additions & 12 deletions scripts/package.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Copyright 2018 The Bazel Authors. All rights reserved.
# Copyright 2024 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -19,18 +19,11 @@ set -eu
# Move into the top-level directory of the project.
cd "$(dirname "${BASH_SOURCE[0]}")/.." > /dev/null

./scripts/build.sh
./scripts/prepare.sh

# Prepare dist/ content besides the entry js.
mkdir -p dist
cp ./package.json ./dist/package.json
cp ./LICENSE ./dist/LICENSE
cp ./README.md ./dist/README.md
cp -r ./icons ./dist/icons
cp -r ./media ./dist/media
cp -r ./syntaxes ./dist/syntaxes
# Do not watch. Drop minify as well before we have a better arg parse here.
node esbuild-debug-adapter.js --production

node esbuild.js --production

cd dist
vsce package --no-dependencies -o ..
vsce package --no-dependencies
35 changes: 35 additions & 0 deletions scripts/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

# Copyright 2024 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu

# Move into the top-level directory of the project.
cd "$(dirname "${BASH_SOURCE[0]}")/.." > /dev/null

# Only regenerate the .js and .t.ds file if the protos have changed (i.e.,
# it's a fresh checkout or update_protos.sh has been executed again and
# deleted the old generated files). This shaves several seconds off the
# extension's build time.
if [[ ! -f src/protos/protos.js ]] ; then
sed -e "s#^#src/protos/#" src/protos/protos_list.txt | \
xargs pbjs -t static-module -o src/protos/protos.js
fi
if [[ ! -f src/protos/protos.d.ts ]] ; then
pbts -o src/protos/protos.d.ts src/protos/protos.js
fi

# Convert yaml language definition to json form requred by vscode.
js-yaml syntaxes/bazelrc.tmLanguage.yaml > syntaxes/bazelrc.tmLanguage.json
5 changes: 2 additions & 3 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ set -eu
# Move into the top-level directory of the project.
cd "$(dirname "${BASH_SOURCE[0]}")/.." > /dev/null

# If tests are eventually added for other things, this line should probably
# be replaced by just running scripts/build.sh.
js-yaml syntaxes/bazelrc.tmLanguage.yaml > syntaxes/bazelrc.tmLanguage.json
# This should be invoked by either `npm test` or `npm run test` in pretest
# implicitly, thus the build build steps are all moved into build.sh.

# Regression test for bazelrc grammar
vscode-tmgrammar-snap "$@" test/example.bazelrc
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
"allowJs": true,
},
"exclude": [
"dist",
"node_modules",
"out",
"esbuild*.js",
"eslint.config.js",
"scripts",
]
Expand Down

0 comments on commit d685dbb

Please sign in to comment.