Skip to content

Commit

Permalink
plugins/typescript-tools: remove with lib and helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman committed Oct 26, 2024
1 parent 2ef948e commit 2a40d08
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions plugins/by-name/typescript-tools/default.nix
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
{
lib,
pkgs,
helpers,
config,
...
}:
with lib;
let
inherit (lib.nixvim) defaultNullOpts;
cfg = config.plugins.typescript-tools;
in
{
options.plugins.typescript-tools = {
enable = mkEnableOption "typescript-tools";
enable = lib.mkEnableOption "typescript-tools";
package = lib.mkPackageOption pkgs "typescript-tools" {
default = [
"vimPlugins"
"typescript-tools-nvim"
];
};

onAttach = helpers.defaultNullOpts.mkLuaFn "__lspOnAttach" "Lua code to run when tsserver attaches to a buffer.";
handlers = mkOption {
onAttach = defaultNullOpts.mkLuaFn "__lspOnAttach" "Lua code to run when tsserver attaches to a buffer.";
handlers = lib.mkOption {
type = with lib.types; nullOr (attrsOf strLuaFn);
default = null;
description = "How tsserver should respond to LSP requests";
Expand All @@ -35,10 +34,10 @@ in
};

settings = {
separateDiagnosticServer = helpers.defaultNullOpts.mkBool true "Spawns an additional tsserver instance to calculate diagnostics";
separateDiagnosticServer = defaultNullOpts.mkBool true "Spawns an additional tsserver instance to calculate diagnostics";

publishDiagnosticOn =
helpers.defaultNullOpts.mkEnum
defaultNullOpts.mkEnum
[
"change"
"insert_leave"
Expand All @@ -48,9 +47,9 @@ in
Either "change" or "insert_leave". Determines when the client asks the server about diagnostics
'';

exposeAsCodeAction = mkOption {
exposeAsCodeAction = lib.mkOption {
type =
with types;
with lib.types;
either (enum [ "all" ]) (
listOf (enum [
"fix_all"
Expand All @@ -65,27 +64,27 @@ in
description = "Specify what to expose as code actions.";
};

tsserverPath = helpers.mkNullOrStr ''
tsserverPath = lib.nixvim.mkNullOrStr ''
Specify a custom path to `tsserver.js` file, if this is nil or file under path
doesn't exist then standard path resolution strategy is applied
'';

tsserverPlugins =
with lib.types;
helpers.mkNullOrOption (listOf (maybeRaw str)) ''
lib.nixvim.mkNullOrOption (listOf (maybeRaw str)) ''
List of plugins for tsserver to load. See this plugins's README
at https://github.com/pmizio/typescript-tools.nvim/#-styled-components-support
'';

tsserverMaxMemory =
helpers.mkNullOrOption (with lib.types; maybeRaw (either ints.unsigned (enum [ "auto" ])))
lib.nixvim.mkNullOrOption (with lib.types; maybeRaw (either ints.unsigned (enum [ "auto" ])))
''
This value is passed to: https://nodejs.org/api/cli.html#--max-old-space-sizesize-in-megabytes
Memory limit in megabytes or "auto"(basically no limit)
'';

tsserverFormatOptions = mkOption {
type = with types; nullOr (attrsOf anything);
tsserverFormatOptions = lib.mkOption {
type = with lib.types; nullOr (attrsOf anything);
default = null;
description = "Configuration options that well be passed to the tsserver instance. Find available options [here](https://github.com/microsoft/TypeScript/blob/v5.0.4/src/server/protocol.ts#L3418)";
example = {
Expand All @@ -100,8 +99,8 @@ in
};
};

tsserverFilePreferences = mkOption {
type = with types; nullOr (attrsOf anything);
tsserverFilePreferences = lib.mkOption {
type = with lib.types; nullOr (attrsOf anything);
default = null;
description = "Configuration options that well be passed to the tsserver instance. Find available options [here](https://github.com/microsoft/TypeScript/blob/v5.0.4/src/server/protocol.ts#L3439)";
example = {
Expand All @@ -114,20 +113,20 @@ in
};
};

tsserverLocale = helpers.defaultNullOpts.mkStr "en" ''
tsserverLocale = defaultNullOpts.mkStr "en" ''
Locale of all tsserver messages. Supported locales here: https://github.com/microsoft/TypeScript/blob/3c221fc086be52b19801f6e8d82596d04607ede6/src/compiler/utilitiesPublic.ts#L620
'';

completeFunctionCalls = helpers.defaultNullOpts.mkBool false ''
completeFunctionCalls = defaultNullOpts.mkBool false ''
Mirror of VSCode's `typescript.suggest.completeFunctionCalls`
'';

includeCompletionsWithInsertText = helpers.defaultNullOpts.mkBool true ''
includeCompletionsWithInsertText = defaultNullOpts.mkBool true ''
Mirror of VSCode's `typescript.suggest.completeFunctionCalls`
'';

codeLens =
helpers.defaultNullOpts.mkEnum
defaultNullOpts.mkEnum
[
"off"
"all"
Expand All @@ -137,16 +136,16 @@ in
"off"
"WARNING: Experimental feature also in VSCode, disabled by default because it might impact server performance.";

disableMemberCodeLens = helpers.defaultNullOpts.mkBool true ''
disableMemberCodeLens = defaultNullOpts.mkBool true ''
By default code lenses are displayed on all referenceable values. Display less by removing member references from lenses.
'';

jsxCloseTag = {
enable = helpers.defaultNullOpts.mkBool false ''
enable = defaultNullOpts.mkBool false ''
Functions similarly to `nvim-ts-autotag`. This is disabled by default to avoid conflicts.
'';
filetypes =
helpers.defaultNullOpts.mkListOf types.str
defaultNullOpts.mkListOf lib.types.str
[
"javascriptreact"
"typescriptreact"
Expand All @@ -157,7 +156,7 @@ in
};
};
};
config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
extraPlugins = [ cfg.package ];

plugins.lsp.postConfig =
Expand Down Expand Up @@ -188,7 +187,7 @@ in
};
in
''
require('typescript-tools').setup(${helpers.toLuaObject options})
require('typescript-tools').setup(${lib.nixvim.toLuaObject options})
'';
};
}

0 comments on commit 2a40d08

Please sign in to comment.