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 cfdbbad commit 4b02cf9
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 201 deletions.
2 changes: 0 additions & 2 deletions lua/ht/conf/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
local all_servers = (function()
local servers = {}

servers[#servers + 1] = require("ht.conf.lsp.servers.clangd")
servers[#servers + 1] = require("ht.conf.lsp.servers.rust-analyzer")
servers[#servers + 1] = require("ht.conf.lsp.servers.pyright")
servers[#servers + 1] = require("ht.conf.lsp.servers.cmake")
servers[#servers + 1] = require("ht.conf.lsp.servers.lua_ls")
servers[#servers + 1] = require("ht.conf.lsp.servers.rime_ls")
-- servers[#servers + 1] = require("ht.conf.lsp.servers.tsserver")
servers[#servers + 1] = require("ht.conf.lsp.servers.flutter")

-- init sourcekit in macos
Expand Down
141 changes: 0 additions & 141 deletions lua/ht/conf/lsp/servers/clangd.lua

This file was deleted.

88 changes: 88 additions & 0 deletions src/conf/external_tools/lsp_servers/clangd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { LspServer } from "@core/model";
import { HttsContext } from "context";

function wrapOnAttach(defaultCallback: (client: any, bufnr: number) => void) {
return (client: unknown, bufnr: number) => {
defaultCallback(client, bufnr);

vim.keymap.set(
"n",
"<leader>fa",
() => {
vim.api.nvim_command("ClangdSwitchSourceHeader");
},
{
desc: "clangd-switch-header",
buffer: bufnr,
}
);
};
}

export const server = new LspServer({
name: "clangd",
exe: {
masonPkg: "clangd",
},
setup(_server: LspServer, on_attach: () => void, capabilities: LuaTable) {
luaRequire("lspconfig").clangd.setup({
cmd: [
`${HttsContext.getInstance().masonBinRoot}/clangd`,
"--clang-tidy",
"--background-index",
"--background-index-priority=normal",
"--ranking-model=decision_forest",
"--completion-style=detailed",
"--header-insertion=iwyu",
"--limit-references=100",
"--limit-results=100",
"--include-cleaner-stdlib",
"-j=20",
],
on_attach: wrapOnAttach(on_attach),
capabilities: capabilities,
filetypes: ["c", "cpp"],
});

luaRequire("clangd_extensions").setup({
extensions: {
autoSetHints: false,
hover_with_actions: true,
inlay_hints: {
inline: false,
only_current_line: false,
only_current_line_autocmd: "CursorHold",
show_parameter_hints: false,
show_variable_name: true,
other_hints_prefix: "",
max_len_align: false,
max_len_align_padding: 1,
right_align: false,
right_align_padding: 7,
highlight: "Comment",
},
ast: {
role_icons: {
type: "🄣",
declaration: "🄓",
expression: "🄔",
statement: ";",
specifier: "🄢",
["template argument"]: "🆃",
},
kind_icons: {
Compound: "🄲",
Recovery: "🅁",
TranslationUnit: "🅄",
PackExpansion: "🄿",
TemplateTypeParm: "🅃",
TemplateTemplateParm: "🅃",
TemplateParamObject: "🅃",
},
},
memory_usage: { border: "rounded" },
symbol_info: { border: "rounded" },
},
});
},
});
5 changes: 3 additions & 2 deletions src/conf/external_tools/lsp_servers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import TypescriptTool from "./typescript-tools";
import typescriptTool from "./typescript-tools";
import { server as clangdTool } from "./clangd";

export default [TypescriptTool];
export default [typescriptTool, clangdTool];
55 changes: 55 additions & 0 deletions src/conf/plugins/lsp/clangd_extensions-nvim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
ActionGroupBuilder,
Plugin,
PluginOptsBase,
andActions,
} from "@core/model";

const spec: PluginOptsBase = {
shortUrl: "p00f/clangd_extensions.nvim",
lazy: {
lazy: true,
},
};

function generateActions() {
return ActionGroupBuilder.start()
.category("Clangd")
.from("clangd_extensions.nvim")
.condition((buf) => {
for (let server of buf.lspServers) {
if (server.name === "clangd") {
return true;
}
}
return false;
})
.addOpts({
id: "clangd.switch-source-header",
title: "Switch between source and header files",
callback: "ClangdSwitchSourceHeader",
})
.addOpts({
id: "clangd.view-ast",
title: "View AST",
callback: "ClangdAST",
})
.addOpts({
id: "clangd.view-type-hierarchy",
title: "View type hierarchy",
callback: "ClangdTypeHierarchy",
})
.addOpts({
id: "clangd.symbol-info",
title: "Symbol info",
callback: "ClangdSymbolInfo",
})
.addOpts({
id: "clangd.memory-usage",
title: "Memory usage",
callback: "ClangdMemoryUsage",
})
.build();
}

export const plugin = new Plugin(andActions(spec, generateActions));
2 changes: 2 additions & 0 deletions src/conf/plugins/lsp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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";
import { plugin as clangdExtensionsNvim } from "./clangd_extensions-nvim";

export const plugins = [
mason,
Expand All @@ -12,4 +13,5 @@ export const plugins = [
glanceNvim,
lspkindNvim,
troubleNvim,
clangdExtensionsNvim,
] as const;
Loading

0 comments on commit 4b02cf9

Please sign in to comment.