Skip to content

Commit

Permalink
Working on go dap
Browse files Browse the repository at this point in the history
  • Loading branch information
wiltaylor committed May 17, 2021
1 parent b549b5d commit 63897c4
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 4 deletions.
116 changes: 116 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
lightline-vim = { url = "github:itchyny/lightline.vim"; flake = false; };
nvim-lspconfig = { url = "github:neovim/nvim-lspconfig"; flake = false; };
completion-nvim = { url = "github:nvim-lua/completion-nvim"; flake = false; };
vim-nix = { url = "github:LnL7/vim-nix"; flake = false; };
nvim-dap = { url = github:mfussenegger/nvim-dap; flake = false; };

# Nix LSP
rnix-lsp.url = github:nix-community/rnix-lsp;
};

outputs = { nixpkgs, flake-utils, neovim, ... }@inputs:
Expand All @@ -30,6 +35,8 @@
"lightline-vim"
"nvim-lspconfig"
"completion-nvim"
"vim-nix"
"nvim-dap"
];

pluginOverlay = lib.buildPluginOverlay;
Expand All @@ -41,6 +48,7 @@
pluginOverlay
(final: prev: {
neovim-nightly = neovim.defaultPackage.${system};
rnix-lsp = inputs.rnix-lsp.defaultPackage.${system};
})
];
};
Expand Down Expand Up @@ -72,7 +80,8 @@
vim.statusline.lightline.enable = true;
vim.lsp.enable = true;
vim.lsp.bash = true;

vim.lsp.go = true;
vim.lsp.nix = true;
};
};
});
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module testbob

go 1.15
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import ( "fmt" )

func main() {
fmt.Println("Hey")
x := 7
foo()

fmt.Printf("%d", x)
}

func foo() {
}
90 changes: 87 additions & 3 deletions modules/lsp/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ in {
enable = mkEnableOption "Enable lsp support";

bash = mkEnableOption "Enable Bash Language Support";
go = mkEnableOption "Enable Go Language Support";
nix = mkEnableOption "Enable NIX Language Support";

};

config = mkIf cfg.enable {
vim.startPlugins = with pkgs.neovimPlugins; [ nvim-lspconfig completion-nvim ];

# ["${pkgs.nodePackages.bash-language-server}/bin/bash-language-server" "start"];
vim.startPlugins = with pkgs.neovimPlugins; [
nvim-lspconfig
completion-nvim
nvim-dap
(if cfg.nix then vim-nix else null)
];

vim.configRC = ''
" Use <Tab> and <S-Tab> to navigate through popup menu
Expand All @@ -27,18 +32,97 @@ in {
set completeopt=menuone,noinsert,noselect
'';

vim.nnoremap = {
"<f2>" = "<cmd>lua vim.lsp.buf.rename()<cr>";
"<leader>r" = "<cmd>lua vim.lsp.buf.rename()<cr>";
"<leader>d" = "<cmd>lua vim.lsp.buf.type_definition()<cr>";
"<leader>e" = "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<cr>";
"<leader>f" = "<cmd>lua vim.lsp.buf.formatting()<CR>";
"<leader>k" = "<cmd>lua vim.lsp.buf.signature_help()<CR>";

gD = "<cmd>lua vim.lsp.buf.declaration()<CR>";
gd = "<cmd>lua vim.lsp.buf.definition()<CR>";
gi = "<cmd>lua vim.lsp.buf.implementation()<CR>";
gr = "<cmd>lua vim.lsp.buf.references()<CR>";
K = "<cmd>lua vim.lsp.buf.hover()<CR>";

"[d" = "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>";
"]d" = "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>";

"<leader>q" = "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>";

# dap
"<F10>" = "lua require'dap'.step_over()<cr>";
"<F11>" = "lua require'dap'.step_into()<cr>";
"<F12>" = "lua require'dap'.step_out()<cr>";
"<F5>" = "lua require'dap'.continue()<cr>";
"<leader>b" = "lua require'dap'.toggle_breakpoint()<cr>";
};

vim.globals = {
};

vim.luaConfigRC = ''
local lspconfig = require'lspconfig'
local dap = require "dap"
${if cfg.bash then ''
lspconfig.bashls.setup{
on_attach=require'completion'.on_attach;
cmd = {"${pkgs.nodePackages.bash-language-server}/bin/bash-language-server", "start"}
}
'' else ""}
${if cfg.go then ''
lspconfig.gopls.setup{
on_attach=require'completion'.on_attach;
cmd = {"${pkgs.gopls}/bin/gopls"}
}
dap.adapters.go = function(callback, config)
local handle
local pid_or_err
local port = 38697
handle, pid_or_err =
vim.loop.spawn(
"dlv",
{
args = {"dap", "-l", "127.0.0.1:" .. port},
detached = true
},
function(code)
handle:close()
print("Delve exited with exit code: " .. code)
end
)
-- Wait 100ms for delve to start
vim.defer_fn(
function()
--dap.repl.open()
callback({type = "server", host = "127.0.0.1", port = port})
end,
100)
--callback({type = "server", host = "127.0.0.1", port = port})
end
-- https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_dap.md
dap.configurations.go = {
{
type = "go",
name = "Debug",
request = "launch",
program = "${pkgs.delve}/bin/delve"
}
}
'' else ""}
${if cfg.nix then ''
lspconfig.rnix.setup{
on_attach=require'completion'.on_attach;
cmd = {"${pkgs.rnix-lsp}/bin/rnix-lsp"}
}
'' else ""}
'';
};
}
3 changes: 3 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/sh

echo "test"
export TEST="Bar"

echo "$TEST"

0 comments on commit 63897c4

Please sign in to comment.