From ab864c4c17cbbf922288bb7cb2f4ce9a325654c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Brelih?= Date: Mon, 2 May 2022 00:47:45 +0200 Subject: [PATCH] feat: added command to close floating term (#119) * feat: added command to close floating term * feat: automatically close previous float term * Update go.lua remove auto complete Co-authored-by: Ales Brelih Co-authored-by: rayx --- README.md | 15 +++++++++++---- doc/go.txt | 3 +++ lua/go.lua | 7 +++++++ lua/go/term.lua | 2 ++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9ca000e..b0efcd2 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,12 @@ require('go').setup() ![gotest](https://user-images.githubusercontent.com/1681295/143160335-b8046ffa-82cd-4d84-af3e-3b0dbb4c609e.png) +Use: +```vim +:GoTermClose +``` +To close the floating term. + ## refactor gorename gorename as an alternative to gopls rename as it supports rename across packages @@ -190,16 +196,17 @@ first run of `GoFmt` may fail. It is recommended to run `GoInstallBinaries` to i | GoBuild | | | GoGenerate | | | GoRun | e.g. GoRun equal to `go run .`; or `GoRun ./cmd` equal to `go run ./cmd` | -| GoStop {job_id} | `stop the job started with GoRun | +| GoStop {job_id} | `stop the job started with GoRun` | | GoTest | go test ./... | | GoTest -c | go test -c current_file_path | | GoTest -tags=yourtags | go test ./... -tags=yourtags | | GoTest package_path -tags=yourtags | go test packagepath -tags=yourtags | | GoTest package_path -tags=yourtags other_args | go test packagepath -tags=yourtags other_args | | GoLint | golangci-lint | -| GoGet {package_url} | go get package_url and restart gopls. Note1 | +| GoGet {package_url} | go get package_url and restart gopls. Note1 | | GoVet | go vet | | GoCoverage | go test -coverprofile | +| GoTermClose | `closes the floating term` | Note1: if package_url not provided, will check current line is a valid package url or not, if it is valid, will fetch current url @@ -497,8 +504,8 @@ require('go').setup({ build_tags = "tag1,tag2", -- set default build tags textobjects = true, -- enable default text jobects through treesittter-text-objects test_runner = 'go', -- richgo, go test, richgo, dlv, ginkgo - run_in_floaterm = false, -- set to true to run in float window. - --float term recommand if you use richgo/ginkgo with terminal color + run_in_floaterm = false, -- set to true to run in float window. :GoTermClose closes the floatterm + -- float term recommand if you use richgo/ginkgo with terminal color }) ``` diff --git a/doc/go.txt b/doc/go.txt index 0327113..faffcac 100644 --- a/doc/go.txt +++ b/doc/go.txt @@ -270,6 +270,9 @@ COMMANDS *go-nvim-commands* e.g. GoImpl {receiver} {interface}, will check if cursor is a valid receiver, if you park cursor on struct name, receiver can be omitted. e.g ":GoImpl io.Reader", or "GoImpl f *File io.Reader" + +:GoTermClose + Closes the floating term. ============================================================================== OPTIONS *go-nvim-options* diff --git a/lua/go.lua b/lua/go.lua index 7d5022a..95699d1 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -117,6 +117,7 @@ function go.setup(cfg) [[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoTest lua require('go.gotest').test()]] ) + vim.cmd( [[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoCoverage lua require'go.coverage'.run()]] ) @@ -195,6 +196,12 @@ function go.setup(cfg) vim.cmd([[command! GoDbgStop lua require'go.dap'.stop()]]) end + if _GO_NVIM_CFG.run_in_floaterm then + vim.cmd( + [[command! -nargs=* GoTermClose lua require("go.term").close()]] + ) + end + if _GO_NVIM_CFG.lsp_cfg then require("go.lsp").setup() if _GO_NVIM_CFG.lsp_diag_hdlr then diff --git a/lua/go/term.lua b/lua/go/term.lua index 031d776..b57d495 100644 --- a/lua/go/term.lua +++ b/lua/go/term.lua @@ -20,6 +20,8 @@ local function close_float_terminal() end local term = function(opts) + close_float_terminal() + local columns = api.nvim_get_option("columns") local lines = api.nvim_get_option("lines")