1
1
mirror of https://github.com/oxalica/nil.git synced 2024-11-22 11:22:46 +03:00

Init coc.nvim extension

This commit is contained in:
oxalica 2023-02-26 06:30:07 +08:00
parent d4e6677846
commit 128a699e5f
12 changed files with 3714 additions and 28 deletions

View File

@ -4,7 +4,9 @@ let
customRC = ''
source ${./vimrc.vim}
let $COC_NO_PLUGINS = 1
if !empty($COC_NIL_PATH)
execute 'set rtp^=' . $COC_NIL_PATH
endif
autocmd BufRead,BufNewFile *.nix setf nix
@ -83,21 +85,15 @@ let
'';
cocSetting = {
"coc.preferences.formatOnSaveFiletypes" = [ "nix" ];
"links.tooltip" = true;
coc.preferences.formatOnSaveFiletypes = [ "nix" ];
links.tooltip = true;
semanticTokens.filetypes = [ "nix" ];
languageserver.nix = {
command = pkgs.writeShellScript "nil" ''
nil.server.path = pkgs.writeShellScript "nil" ''
exec "$NIL_PATH" "$@"
'';
filetypes = [ "nix" ];
rootPatterns = [ "flake.nix" ];
settings.nil = {
testSetting = 42;
formatting.command = [ "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt" ];
diagnostics.excludedFiles = [ "generated.nix" ];
};
};
nil.formatting.command = [ "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt" ];
nil.diagnostics.excludedFiles = [ "generated.nix" ];
};
@ -115,6 +111,7 @@ pkgs.vim_configurable.customize {
packages.myPlugins.start = with pkgs.vimPlugins; [
vim-nix # File type and syntax highlighting.
coc-nvim
coc-json
# FIXME
(nightfox-nvim.overrideAttrs (old: {
src = pkgs.fetchFromGitHub {

View File

@ -0,0 +1,16 @@
module.exports = {
env: {
node: true,
},
parser: '@typescript-eslint/parser',
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
};

2
editors/coc-nil/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/node_modules
/lib

View File

@ -0,0 +1,11 @@
src
node_modules
tsconfig.json
*.map
.tags
.DS_Store
webpack.config.js
esbuild.js
.github
.eslintrc.js
.prettierrc

View File

@ -0,0 +1 @@
../../LICENSE-APACHE

1
editors/coc-nil/LICENSE-MIT Symbolic link
View File

@ -0,0 +1 @@
../../LICENSE-MIT

37
editors/coc-nil/README.md Normal file
View File

@ -0,0 +1,37 @@
# coc-nil
**WIP**
[nil] language server glue for Vim/Neovim, works as an extension with [coc.nvim].
[nil]: https://github.com/oxalica/nil
[coc.nvim]: https://github.com/neoclide/coc.nvim
## Install
`:CocInstall coc-nil`
## Configurations
This extension is configured using a jsonc file. You can open this configuration file using the command `:CocConfig`,
and it is typically located at `$HOME/.config/nvim/coc-settings.json`.
Configurations to the LSP is documentated in
[`docs/configuration.md` of the LSP repository](https://github.com/oxalica/nil/blob/main/docs/configuration.md#reference),
with the exception that configuration keys can **ALSO** be written as flattened dot-separated string key.
That is, `coc-nvim` supports `"nil.nix.binary": "nix"`, `"nil": { "nix": { "binary": "nix" } }"`,
and even `"nil": { "nix.binary": "nix" }`.
The table below shows all extra configurations for the extension itself.
| Configuration | Description | Default |
|---|---|---|
| `nil.enable` | Enable `coc-nil` | `true` |
| `nil.server.path` | Path to the `nil` LSP server | `"nil"` |
## License
"coc-nil" is primarily distributed under the terms of both the MIT
license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.

3465
editors/coc-nil/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,100 @@
{
"name": "coc-nil",
"version": "0.0.0",
"description": "Nix extension using nil LSP for coc.nvim",
"author": "oxalica <oxalicc@pm.me>",
"license": "MIT OR Apache-2.0",
"main": "lib/main.js",
"keywords": [
"coc.nvim"
],
"engines": {
"coc": "^0.0.80"
},
"scripts": {
"clean": "rimraf lib",
"lint": "eslint src --ext ts",
"build": "esbuild src/main.ts --bundle --platform=node --target=node14 --external:coc.nvim --outdir=lib --color=false",
"watch": "esbuild src/main.ts --bundle --platform=node --target=node14 --external:coc.nvim --outdir=lib --color=false --watch",
"prepare": "npm run clean && npm run build"
},
"prettier": {
"singleQuote": true,
"printWidth": 120,
"semi": true
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.53.0",
"coc.nvim": "^0.0.82",
"esbuild": "^0.17.10",
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.8.4",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
},
"activationEvents": [
"onLanguage:nix"
],
"contributes": {
"rootPatterns": [
{
"filetype": "nix",
"patterns": [
"flake.nix"
]
}
],
"configuration": {
"type": "object",
"title": "coc-nil configuration",
"properties": {
"nil.enable": {
"type": "boolean",
"default": true,
"description": "Enable `coc-nil` extension"
},
"nil.server.path": {
"type": "string",
"default": "nil",
"description": "Path to the `nil` LSP server"
},
"nil.formatting.command": {
"type": [
"null",
"array"
],
"items": {
"type": "string"
},
"default": "null",
"description": "External formatter command with arguments"
},
"nil.diagnostics.ignored": {
"type": "string",
"items": {
"type": "string"
},
"default": [],
"description": "Ignored diagnostic kinds"
},
"nil.diagnostics.excludedFiles": {
"type": "string",
"items": {
"type": "string"
},
"default": [],
"description": "File globs to exclude from showing diagnostics"
},
"nil.nix.binary": {
"type": "string",
"default": "nix",
"description": "The path to the `nix` binary"
}
}
},
"commands": []
}
}

View File

@ -0,0 +1,19 @@
import { ExtensionContext, services, LanguageClient, workspace } from 'coc.nvim';
const ROOT_SECTION = 'nil';
export async function activate(context: ExtensionContext): Promise<void> {
const cfg = workspace.getConfiguration(ROOT_SECTION);
if (!cfg.get('enable', true)) {
return;
}
const serverOptions = {
command: cfg.get<string>('server.path', 'nil'),
};
const clientOptions = {
documentSelector: [{ language: 'nix' }],
};
const client = new LanguageClient('nil', 'nil Language Server', serverOptions, clientOptions);
context.subscriptions.push(services.registLanguageClient(client));
}

View File

@ -0,0 +1,15 @@
{
"compilerOptions": {
"noEmit": true,
"target": "ES2018",
"module": "commonjs",
"declaration": false,
"sourceMap": true,
"outDir": "lib",
"strict": true,
"moduleResolution": "node",
"noImplicitAny": true,
"esModuleInterop": true
},
"include": ["src"]
}

View File

@ -10,14 +10,15 @@
};
outputs = { self, flake-utils, nixpkgs, rust-overlay }:
let
mkNil = { rustPlatform, nix, ... }:
let
inherit (builtins) substring;
inherit (nixpkgs) lib;
mtime = self.lastModifiedDate;
date = "${substring 0 4 mtime}-${substring 4 2 mtime}-${substring 6 2 mtime}";
rev = self.rev or (throw "Git changes are not committed");
in
mkNil = { rustPlatform, nix, ... }:
rustPlatform.buildRustPackage {
pname = "nil";
version = "unstable-${date}";
@ -28,12 +29,23 @@
CFG_RELEASE = "git-${rev}";
};
mkCocNil = { runCommand, nodejs, esbuild }:
runCommand "coc-nil-unstable-${date}" {
nativeBuildInputs = [ nodejs esbuild ];
src = ./editors/coc-nil;
} ''
cp -r --no-preserve=all $src ./source
cd source
npm run build --offline
mkdir -p $out
cp -rt $out lib package{,-lock}.json
'';
in
flake-utils.lib.eachDefaultSystem
(system:
let
inherit (nixpkgs) lib;
pkgs = nixpkgs.legacyPackages.${system};
rustPkgs = rust-overlay.packages.${system};
@ -55,14 +67,16 @@
|| die 'Format failed'
cargo clippy --all --all-targets -- ${clippyFlags} \
|| die 'Clippy failed'
( cd editors/coc-nil; npm run lint )
'';
nil = pkgs.callPackage mkNil { };
in
rec {
packages = {
inherit nil;
packages = rec {
default = nil;
nil = pkgs.callPackage mkNil { };
coc-nil = pkgs.callPackage mkCocNil { };
};
devShells.default = pkgs.mkShell {
@ -79,6 +93,8 @@
# If you do want a locked one, use `devShells.full` below.
# nix.out
nodejs
jq
pre-commit
nixpkgs-fmt
@ -98,6 +114,7 @@
# bash
shellHook = ''
export NIL_PATH="$(cargo metadata --format-version=1 | jq -r .target_directory)/debug/nil"
export COC_NIL_PATH="$(realpath ./editors/coc-nil)"
'';
};
@ -124,12 +141,17 @@
'';
};
})
// rec {
// {
overlays = {
default = lib.composeExtension self.overlays.nil self.overlays.coc-nil;
nil = final: prev: {
nil = final.callPackage mkNil { };
};
default = overlays.nil;
coc-nil = final: prev: {
vimPlugins = prev.vimPlugins or { } // {
coc-nil = final.callPackage mkCocNil { };
};
};
};
};
}