Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
TwIStOy committed Nov 26, 2023
1 parent 47452bd commit cfdbbad
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 113 deletions.
2 changes: 1 addition & 1 deletion lua/ht/plugins/lsp/neodim.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
return {
{
"TwIStOy/neodim",
"zbirenbaum/neodim",
lazy = true,
event = "LspAttach",
config = function()
Expand Down
34 changes: 0 additions & 34 deletions lua/ht/plugins/lsp/null-ls.lua

This file was deleted.

1 change: 0 additions & 1 deletion lua/ht/plugins/lsp/nvim-lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ return {
"hrsh7th/nvim-cmp",
"williamboman/mason.nvim",
"MunifTanjim/nui.nvim",
"jose-elias-alvarez/null-ls.nvim",
},
config = function()
--- add menus for specific types
Expand Down
63 changes: 0 additions & 63 deletions lua/ht/plugins/lsp/trouble.lua

This file was deleted.

11 changes: 1 addition & 10 deletions src/conf/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AllPlugins } from "@conf/plugins";
import { Plugin, PluginActionIds, TraitActionsId } from "@core/model";
import { TupleToUnion } from "@core/type_traits";
import { RemoveReadonlyFromTuple, TupleToUnion } from "@core/type_traits";
import { builtinActions } from "./builtin";

export type AvailableActions = TupleToUnion<
Expand All @@ -25,15 +25,6 @@ type MaybePluginOrPluginList<P> = P extends Plugin<any>[]
? PluginActionIds<P>
: never;

type RemoveReadonlyFromTuple<T extends readonly any[]> = T extends readonly [
infer A,
...infer Rest,
]
? A extends readonly any[]
? [RemoveReadonlyFromTuple<A>, ...RemoveReadonlyFromTuple<Rest>]
: [A, ...RemoveReadonlyFromTuple<Rest>]
: T;

type MergePluginsActions<Ps extends Plugin<any>[]> = Ps extends [
infer P,
...infer Rest,
Expand Down
1 change: 0 additions & 1 deletion src/conf/plugins/coding/crates-nvim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const spec: PluginOptsBase = {
lazy: true,
dependencies: [
"nvim-lua/plenary.nvim",
"jose-elias-alvarez/null-ls.nvim",
"MunifTanjim/nui.nvim",
],
event: {
Expand Down
2 changes: 2 additions & 0 deletions src/conf/plugins/lsp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { plugin as aerial } from "./aerial";
import { plugin as typescriptToolsNvim } from "./typescript-tools-nvim";
import { plugin as glanceNvim } from "./glance-nvim";
import { plugin as lspkindNvim } from "./lspkind-nvim";
import { plugin as troubleNvim } from "./trouble-nvim";

export const plugins = [
mason,
aerial,
typescriptToolsNvim,
glanceNvim,
lspkindNvim,
troubleNvim,
] as const;
93 changes: 93 additions & 0 deletions src/conf/plugins/lsp/trouble-nvim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import {
ActionGroupBuilder,
Plugin,
PluginOptsBase,
andActions,
removeReadonly,
} from "@core/model";

const spec: PluginOptsBase = {
shortUrl: "folke/trouble.nvim",
lazy: {
dependencies: ["folke/lsp-colors.nvim"],
lazy: true,
cmd: ["Trouble", "TroubleClose", "TroubleToggle", "TroubleRefresh"],
},
};

function generateActions() {
const lspActions = ActionGroupBuilder.start()
.category("Trouble")
.from("trouble.nvim")
.condition((buf) => {
return buf.lspServers.length > 0;
})
.addOpts({
id: "trouble.open-workspace-diagnostic",
title: "Open workspace diagnostic (Trouble)",
callback: "Trouble workspace_diagnostic",
keys: {
[1]: "<leader>xw",
desc: "lsp-workspace-diagnostic",
},
})
.addOpts({
id: "trouble.open-document-diagnostic",
title: "Open document diagnostic (Trouble)",
callback: "Trouble document_diagnostic",
keys: {
[1]: "<leader>xd",
desc: "lsp-document-diagnostic",
},
})
.build();
const commonActions = ActionGroupBuilder.start()
.category("Trouble")
.from("trouble.nvim")
.addOpts({
id: "trouble.toggle-indow",
title: "Toggle trouble window",
callback: "TroubleToggle",
keys: {
[1]: "<leader>xx",
desc: "trouble-toggle",
},
})
.build();
const actionsInTroubleWindow = ActionGroupBuilder.start()
.category("Trouble")
.from("trouble.nvim")
.condition(() => {
return luaRequire("trouble").is_open();
})
.addOpts({
id: "trouble.previous-trouble",
title: "Previous trouble item",
callback: () => {
luaRequire("trouble").previous({ skip_groups: true, jump: true });
},
keys: {
[1]: "[q]",
desc: "previous-trouble",
},
})
.addOpts({
id: "trouble.next-trouble",
title: "Next trouble item",
callback: () => {
luaRequire("trouble").next({ skip_groups: true, jump: true });
},
keys: {
[1]: "]q]",
desc: "next-trouble",
},
})
.build();
return removeReadonly([
...lspActions,
...commonActions,
...actionsInTroubleWindow,
] as const);
}

export const plugin = new Plugin(andActions(spec, generateActions));
13 changes: 12 additions & 1 deletion src/core/model/action.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { GetRequired, Push, TupleToUnion } from "@core/type_traits";
import {
GetRequired,
Push,
RemoveReadonlyFromTuple,
TupleToUnion,
} from "@core/type_traits";
import { VimBuffer } from "@core/vim";
import { LazyKeySpec } from "types/plugin/lazy";

Expand Down Expand Up @@ -275,3 +280,9 @@ export class Action<Id extends string> {
return ret;
}
}

export function removeReadonly<T extends readonly any[]>(
actions: T
): RemoveReadonlyFromTuple<T> {
return actions as any;
}
7 changes: 7 additions & 0 deletions src/core/type_traits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ export type Writeable<T> = { -readonly [P in keyof T]: T[P] };
export type DeepWriteable<T> = {
-readonly [P in keyof T]: DeepWriteable<T[P]>;
};

export type RemoveReadonlyFromTuple<T extends readonly any[]> =
T extends readonly [infer A, ...infer Rest]
? A extends readonly any[]
? [RemoveReadonlyFromTuple<A>, ...RemoveReadonlyFromTuple<Rest>]
: [A, ...RemoveReadonlyFromTuple<Rest>]
: T;
1 change: 0 additions & 1 deletion src/core/utils/fn.ts
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

29 changes: 29 additions & 0 deletions src/core/utils/fs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { VimBuffer, system } from "@core/vim";

export async function inGitRepo(buffer?: VimBuffer): Promise<boolean> {
let cwd: string | undefined;
if (buffer && buffer.fullFileName) {
cwd = vim.fn.fnamemodify(buffer.fullFileName, ":h");
}
let ret = await system(["git", "rev-parse", "--is-inside-work-tree"], {
cwd,
});
return ret.code === 0;
}

export async function getCurrentRepoPath(
buffer?: VimBuffer
): Promise<string | null> {
let cwd: string | undefined;
if (buffer && buffer.fullFileName) {
cwd = vim.fn.fnamemodify(buffer.fullFileName, ":h");
}
let ret = await system(["git", "rev-parse", "--show-toplevel"], {
cwd,
});
if (ret.code !== 0) {
return null;
}
return ret.stdout!.trim();
}

16 changes: 16 additions & 0 deletions src/core/vim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,19 @@ export function highlightFg(group: string): string {
}
return "";
}

export function system(
cmd: string[],
opts?: any
): Promise<vim.SystemCompleted> {
return new Promise<vim.SystemCompleted>((resolve, reject) => {
const onExit = (obj: vim.SystemCompleted) => {
resolve(obj);
};
try {
vim.system(cmd, opts, onExit);
} catch (e) {
reject(e);
}
});
}
6 changes: 5 additions & 1 deletion src/types/vim/fn.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ declare namespace vim {
list?: boolean
): string;

export function fnamemodify(fname: string, mods: string): string;
export function fnamemodify(
this: void,
fname: string,
mods: string
): string;

export function setreg(reg: string, val: any, options?: any): void;
}
Expand Down

0 comments on commit cfdbbad

Please sign in to comment.