Skip to content

Commit

Permalink
Merge pull request #23 from Myzel394/vs-code-extension
Browse files Browse the repository at this point in the history
feat: Add build script for vs code extension
  • Loading branch information
Myzel394 authored Oct 20, 2024
2 parents 33dfe0a + ff115d8 commit dd9e92f
Show file tree
Hide file tree
Showing 14 changed files with 589 additions and 71 deletions.
85 changes: 77 additions & 8 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
types: [ published ]

jobs:
build-release:
build-server:
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -44,13 +44,6 @@ jobs:
exit 1
fi
- uses: cachix/install-nix-action@v27
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Check Flake
run: nix flake check

- name: Set up Go
uses: actions/setup-go@v5
with:
Expand All @@ -65,3 +58,79 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GH_CONFIGLSP_TOKEN }}

build-extension:
name: Build extension for ${{ matrix.target }}
runs-on: ${{ matrix.os }}
needs:
# Wait for server to build so that we know the checks have passed
- build-server
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-apple-darwin
os: macos-latest
cross: false
- target: aarch64-apple-darwin
os: macos-latest
cross: false

- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
cross: false
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
cross: false

- target: x86_64-pc-windows-msvc
os: windows-latest
cross: false
- target: aarch64-pc-windows-msvc
os: windows-latest
cross: false

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: cachix/install-nix-action@v27
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Check Flake
run: nix flake check

- name: Build extension
run: nix build .#"vs-code-extension"

- name: Rename extension
run: mv result/*.vsix result/$(basename result/*.vsix)-${{ matrix.target }}.vsix

- uses: actions/upload-artifact@v4
with:
path: result/*.vsix

- name: Target to vs code target
id: vscode_target
run: |
if [ "${{ matrix.target }}" = "x86_64-apple-darwin" ]; then
echo "target=darwin-x64" >> $GITHUB_OUTPUT
elif [ "${{ matrix.target }}" = "aarch64-apple-darwin" ]; then
echo "target=darwin-arm64" >> $GITHUB_OUTPUT
elif [ "${{ matrix.target }}" = "x86_64-unknown-linux-gnu" ]; then
echo "target=linux-x64" >> $GITHUB_OUTPUT
elif [ "${{ matrix.target }}" = "aarch64-unknown-linux-gnu" ]; then
echo "target=linux-arm64" >> $GITHUB_OUTPUT
elif [ "${{ matrix.target }}" = "x86_64-pc-windows-msvc" ]; then
echo "target=win32-x64" >> $GITHUB_OUTPUT
elif [ "${{ matrix.target }}" = "aarch64-pc-windows-msvc" ]; then
echo "target=win32-arm64" >> $GITHUB_OUTPUT
fi
- name: Upload extension to VS Code Marketplace
run: nix develop .#"vs-code-extension" --command bash -c "cd result && vsce publish --target ${{ steps.vscode_target.outputs.target }} --packagePath *.vsix"
env:
VSCE_PAT: ${{ secrets.VSCE_TOKEN }}

Empty file added LICENSE.md
Empty file.
44 changes: 38 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"aarch64-windows"
] (system:
let
version = "0.1.0"; # CI:CD-VERSION
version = "0.1.1"; # CI:CD-VERSION
pkgs = import nixpkgs {
inherit system;
overlays = [
Expand All @@ -37,7 +37,7 @@
inputs = [
pkgs.go_1_22
];
server = pkgs.buildGoModule {
serverUncompressed = pkgs.buildGoModule {
nativeBuildInputs = inputs;
pname = "github.com/Myzel394/config-lsp";
version = version;
Expand All @@ -48,11 +48,28 @@
go test -v $(pwd)/...
'';
};
server = pkgs.stdenv.mkDerivation {
name = "config-lsp-${version}";
src = serverUncompressed;
buildInputs = [
pkgs.upx
];
buildPhase = ''
mkdir -p $out/bin
cp $src/bin/config-lsp $out/bin/
chmod +rw $out/bin/config-lsp
# upx is currently not supported for darwin
if [ "${system}" != "x86_64-darwin" ] && [ "${system}" != "aarch64-darwin" ]; then
upx --ultra-brute $out/bin/config-lsp
fi
'';
};
in {
packages = {
default = server;
"vs-code-extension" = let
name = "config-lsp-vs-code-extension";
name = "config-lsp";
node-modules = pkgs.mkYarnPackage {
src = ./vs-code-extension;
name = name;
Expand All @@ -61,13 +78,26 @@
yarnNix = ./vs-code-extension/yarn.nix;

buildPhase = ''
yarn --offline run compile
yarn --offline run compile:prod
'';
installPhase = ''
mv deps/${name}/out $out
cp ${server}/bin/config-lsp $out/
mkdir -p extension
# No idea why this is being created
rm deps/${name}/config-lsp
cp -rL deps/${name}/. extension
cp ${server}/bin/config-lsp extension/out/config-lsp
cd extension && ${pkgs.vsce}/bin/vsce package
mkdir -p $out
cp *.vsix $out
'';
distPhase = "true";

buildInputs = [
pkgs.vsce
];
};
in node-modules;
};
Expand All @@ -83,6 +113,8 @@
devShells."vs-code-extension" = pkgs.mkShell {
buildInputs = [
pkgs.nodejs
pkgs.vsce
pkgs.yarn2nix
];
};
}
Expand Down
2 changes: 1 addition & 1 deletion server/root-handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const lsName = "config-lsp"

// The comment below at the end of the line is required for the CI:CD to work.
// Do not remove it
var version = "0.1.0" // CI:CD-VERSION
var version = "0.1.1" // CI:CD-VERSION

var lspHandler protocol.Handler

Expand Down
17 changes: 0 additions & 17 deletions vs-code-extension/.vscodeignore

This file was deleted.

Empty file added vs-code-extension/LICENSE.md
Empty file.
34 changes: 14 additions & 20 deletions vs-code-extension/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
# LSP Example for Embedded Language using Language Service
# config-lsp for VS Code

Heavily documented sample code for https://code.visualstudio.com/api/language-extensions/embedded-languages#language-services
`config-lsp` provides language support for various config files.
Currently it supports completions, diagnostics, hints, formatting, hover information,
and definition requests.

## Functionality
Install this extension and load your config files in VS Code to get started.

This extension contributes a new language, `html1`. The new language is for illustration purpose and has basic syntax highlighting.
If `config-lsp` is unable to detect the language of your config file, you can manually
specify it by adding a line in the form of:

This Language Server works for `html1` file. HTML1 is like HTML file but has file extension `.html1`. You can create a `test.html1` file to play with below functionalities:
```plaintext
#?lsp.language=<language>
- Completions for HTML tags
- Completions for CSS in `<style>` tag
- Diagnostics for CSS
# For example
## Running the Sample
#?lsp.language=sshconfig
#?lsp.language=fstab
#?lsp.language=aliases
```

- Run `npm install` 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 compile the client and server.
- Switch to the Debug viewlet.
- Select `Launch Client` from the drop down.
- Run the launch config.
- If you want to debug the server as well use the launch configuration `Attach to Server`
- In the [Extension Development Host] instance of VSCode, open a HTML document
- Type `<d|` to try HTML completion
- Type `<style>.foo { c| }</style>` to try CSS completion
- Have `<style>.foo { }</style>` to see CSS Diagnostics
10 changes: 0 additions & 10 deletions vs-code-extension/build-extension.sh

This file was deleted.

57 changes: 57 additions & 0 deletions vs-code-extension/esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const esbuild = require('esbuild');

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

async function main() {
const ctx = await esbuild.context({
entryPoints: ['src/extension.ts'],
bundle: true,
format: 'cjs',
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: 'node',
outfile: 'out/extension.js',
external: ['vscode'],
logLevel: 'silent',
// According to https://github.com/ewanharris/vscode-versions, VS Code ships with NodeJS version 16.14.2
// and according to https://node.green/ this version supports ES2022.
target: "es2022",
plugins: [
/* add to the end of plugins array */
esbuildProblemMatcherPlugin
]
});
if (watch) {
await ctx.watch();
} else {
await ctx.rebuild();
await ctx.dispose();
}
}

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

main().catch(e => {
console.error(e);
process.exit(1);
});
Binary file added vs-code-extension/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dd9e92f

Please sign in to comment.