Skip to content

Instantly share code, notes, and snippets.

@pvdrz
Created March 9, 2023 18:31
Show Gist options
  • Save pvdrz/03183ff6ac848dd95f919d6e517fdde1 to your computer and use it in GitHub Desktop.
Save pvdrz/03183ff6ac848dd95f919d6e517fdde1 to your computer and use it in GitHub Desktop.
Logs
local on_windows = vim.loop.os_uname().version:match 'Windows'
local function join_paths(...)
local path_sep = on_windows and '\\' or '/'
local result = table.concat({ ... }, path_sep)
return result
end
vim.cmd [[set runtimepath=$VIMRUNTIME]]
local temp_dir = vim.loop.os_getenv 'TEMP' or '/tmp'
vim.cmd('set packpath=' .. join_paths(temp_dir, 'nvim', 'site'))
local package_root = join_paths(temp_dir, 'nvim', 'site', 'pack')
local lspconfig_path = join_paths(package_root, 'test', 'start', 'nvim-lspconfig')
if vim.fn.isdirectory(lspconfig_path) ~= 1 then
vim.fn.system { 'git', 'clone', 'https://github.com/neovim/nvim-lspconfig', lspconfig_path }
end
vim.lsp.set_log_level 'trace'
require('vim.lsp.log').set_format_func(vim.inspect)
local nvim_lsp = require 'lspconfig'
local on_attach = function(_, bufnr)
local function buf_set_option(...)
vim.api.nvim_buf_set_option(bufnr, ...)
end
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
local opts = { buffer = bufnr, noremap = true, silent = true }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
end
local name = 'rust_analyzer'
nvim_lsp[name].setup {
on_attach = on_attach,
settings = {
['rust-analyzer'] = {
check = {
invocationLocation = 'root',
invocationStrategy = 'once',
overrideCommand = { 'python3', 'x.py', 'check', '--json-output' },
},
linkedProjects = { 'src/bootstrap/Cargo.toml', 'Cargo.toml' },
rustfmt = {
-- the `x86_64-unknown-linux-gnu` needs to be changed by the host platform
overrideCommand = { './build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt', '--edition=2021' },
},
procMacro = {
-- the `x86_64-unknown-linux-gnu` needs to be changed by the host platform
server = { './build/x86_64-unknown-linux-gnu/stage0/libexec/rust-analyzer-proc-macro-srv' },
enable = true,
},
cargo = {
buildScripts = {
enable = true,
invocationLocation = 'root',
invocationStrategy = 'once',
overrideCommand = { 'python3', 'x.py', 'check', '--json-output' },
},
sysrootSrc = './library',
},
rustc = {
source = './Cargo.toml',
},
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment