Skip to content

Commit

Permalink
Full vscode extension
Browse files Browse the repository at this point in the history
  • Loading branch information
szlend committed Jun 28, 2023
1 parent 78e7a88 commit 5ece996
Show file tree
Hide file tree
Showing 16 changed files with 5,254 additions and 10,198 deletions.
43 changes: 23 additions & 20 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@
pkgs.cargo-insta
pkgs.nixpkgs-fmt
pkgs.nodejs
pkgs.node2nix
pkgs.yarn
pkgs.yarn2nix
pkgs.nodePackages.markdownlint-cli
pkgs.python3
topiary.packages.${system}.default
Expand Down Expand Up @@ -401,25 +402,27 @@
};
};

# Build the Nickel VSCode extension. The extension seems to be required
# for the LSP to work.
vscodeExtension =
let node-package = (pkgs.callPackage ./lsp/client-extension { }).package;
in
(node-package.override rec {
pname = "nls-client";
outputs = [ "vsix" "out" ];
nativeBuildInputs = with pkgs; [
# `vsce` depends on `keytar`, which depends on `pkg-config` and `libsecret`
pkg-config
libsecret
];
postInstall = ''
npm run compile
mkdir -p $vsix
echo y | npx vsce package -o $vsix/${pname}.vsix
'';
}).vsix;
# Build the Nickel VSCode extension
vscodeExtension = pkgs.mkYarnPackage {
pname = "vscode-nickel";
src = pkgs.lib.cleanSource ./lsp/client-extension;

buildPhase = ''
# yarn tries to create a .yarn file in $HOME. There's probably a
# better way to fix this but setting HOME to TMPDIR works for now.
export HOME="$TMPDIR"
cd deps/vscode-nickel
yarn --offline compile
yarn --offline vsce package --yarn -o $pname.vsix
'';

installPhase = ''
mkdir $out
mv $pname.vsix $out
'';

distPhase = "true";
};

# Copy the markdown user manual to $out.
userManual = pkgs.stdenv.mkDerivation {
Expand Down
6 changes: 3 additions & 3 deletions lsp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ NLS is currently not available through the vscode marketplace, but this
repository includes an extension that can be built locally via Nix (see the
section about the Nix setup).

- One-liner (using the [jq](https://stedolan.github.io/jq/) command):
- One-liner:

```console
code --install-extension $(nix build ./\#vscodeExtension --no-link --json | jq ".[0].outputs.vsix")
code --install-extension $(nix build ./\#vscodeExtension --no-link --print-out-paths)/vscode-nickel.vsix
```

- In two steps, going via VSCode:
Expand All @@ -104,7 +104,7 @@ section about the Nix setup).
```

- Then, in VSCode, use "Extension: Install from VSIX" in the vscode command
palette and choose `./result-vsix/nls-client.vsix`.
palette and choose `./result/vscode-nickel.vsix`.

#### Configuration

Expand Down
6 changes: 6 additions & 0 deletions lsp/client-extension/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/*
!out/extension.js
!language-configuration.json
!package.json
!syntaxes/
!LICENSE
21 changes: 21 additions & 0 deletions lsp/client-extension/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Tweag Holding and its affiliates.

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:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

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.
32 changes: 21 additions & 11 deletions lsp/client-extension/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Nickel Language Server Protocol VS Code extension
# Nickel Language VS Code extension

This directory contains the Visual Studio Code Nickel LSP extension code.
## Features

* Syntax highlighting
* Language server
* Code formatting using [Topiary](https://github.com/tweag/topiary)

## Prerequsites

### Install `nickel`, `nls` and `topiary`

```shell
nix profile install nixpkgs#{nickel,nls,topiary}
```

## Build

Expand All @@ -12,29 +24,27 @@ From the root of the Nickel project:
nix build .\#vscodeExtension
```

The VSIX extension will be at `./result-vsix/nls-client.vsix`.
The VSIX extension will be at `./result/vscode-nickel.vsix`.

### With NPM
### With Yarn

From this directory:

```shell
npm install && npm run compile && echo y | npx vsce package
yarn install && yarn compile && yarn vsce package --yarn
```

The VSIX extension will be at `./nls-[version].vsix`.
The VSIX extension will be at `./vscode-nickel-[version].vsix`.

## Updating `package.json`

Whenever you change `package.json`, you must run the following command:

```shell
npm install --package-lock-only && node2nix --development --lock
yarn install && yarn2nix > yarn.nix
```

This will update:

* `package-lock.json`
* `default.nix`
* `node-env.nix`
* `node-packages.nix`
* `yarn.lock`
* `yarn.nix`
17 changes: 0 additions & 17 deletions lsp/client-extension/default.nix

This file was deleted.

32 changes: 32 additions & 0 deletions lsp/client-extension/language-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"comments": {
// symbol used for single line comment. Remove this entry if your language does not support line comments
"lineComment": "#"
},
// symbols used as brackets
"brackets": [
["{", "}"],
["%{", "}"],
["[", "]"],
["[|", "|]"],
["(", ")"]
],
// symbols that are auto closed when typing
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["[|", "|]"],
["(", ")"],
["\"", "\""],
["'", "'"]
],
// symbols that can be used to surround a selection
"surroundingPairs": [
["{", "}"],
["[", "]"],
["[|", "|]"],
["(", ")"],
["\"", "\""],
["'", "'"]
]
}
Loading

0 comments on commit 5ece996

Please sign in to comment.