-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from lukas-reineke/develop
Version 2.4.0
- Loading branch information
Showing
9 changed files
with
305 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
globals = { "vim", "_" } | ||
globals = { "vim", "_", "assert", "describe", "before_each", "after_each", "it" } | ||
max_line_length = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
ifndef VERBOSE | ||
.SILENT: | ||
endif | ||
|
||
specs: dependencies | ||
@echo "Running lsp-format specs..." | ||
timeout 300 nvim -e \ | ||
--headless \ | ||
-u specs/minimal_init.vim \ | ||
-c "PlenaryBustedDirectory specs/features {minimal_init = 'specs/minimal_init.vim'}" | ||
|
||
dependencies: | ||
if [ ! -d vendor ]; then \ | ||
git clone --depth 1 \ | ||
https://github.com/nvim-lua/plenary.nvim \ | ||
vendor/pack/vendor/start/plenary.nvim; \ | ||
git clone --depth 1 \ | ||
https://github.com/neovim/nvim-lspconfig \ | ||
vendor/pack/vendor/start/nvim-lspconfig; \ | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
local mock = require "luassert.mock" | ||
local match = require "luassert.match" | ||
local spy = require "luassert.spy" | ||
local f = require "lsp-format" | ||
|
||
local mock_client = { | ||
id = 1, | ||
name = "lsp-client-test", | ||
request = function(_, _, _, _) end, | ||
request_sync = function(_, _, _, _) end, | ||
supports_method = function(_) end, | ||
setup = function() end, | ||
} | ||
|
||
vim.lsp.buf_get_clients = function() | ||
local clients = {} | ||
clients[mock_client.name] = mock_client | ||
return clients | ||
end | ||
|
||
describe("lsp-format", function() | ||
local c | ||
local api | ||
|
||
before_each(function() | ||
c = mock(mock_client, true) | ||
api = mock(vim.api) | ||
c.supports_method = function(_) | ||
return true | ||
end | ||
f.setup {} | ||
f.on_attach(c) | ||
end) | ||
|
||
after_each(function() | ||
mock.revert(c) | ||
mock.revert(api) | ||
end) | ||
|
||
it("sends a valid format request", function() | ||
f.format {} | ||
assert.stub(c.request).was_called(1) | ||
assert.stub(c.request).was_called_with("textDocument/formatting", { | ||
options = { | ||
insertSpaces = false, | ||
tabSize = 8, | ||
}, | ||
textDocument = { | ||
uri = "file://", | ||
}, | ||
}, match.is_ref(f._handler), 1) | ||
end) | ||
|
||
it("FormatToggle prevent/allow formatting", function() | ||
f.toggle { args = "" } | ||
f.format {} | ||
assert.stub(c.request).was_called(0) | ||
|
||
f.toggle { args = "" } | ||
f.format {} | ||
assert.stub(c.request).was_called(1) | ||
end) | ||
|
||
it("FormatDisable/Enable prevent/allow formatting", function() | ||
f.disable { args = "" } | ||
f.format {} | ||
assert.stub(c.request).was_called(0) | ||
|
||
f.enable { args = "" } | ||
f.format {} | ||
assert.stub(c.request).was_called(1) | ||
end) | ||
|
||
it("sends default format options", function() | ||
f.setup { | ||
lua = { | ||
bool_test = true, | ||
int_test = 1, | ||
string_test = "string", | ||
}, | ||
} | ||
vim.bo.filetype = "lua" | ||
f.format {} | ||
assert.stub(c.request).was_called(1) | ||
assert.stub(c.request).was_called_with("textDocument/formatting", { | ||
options = { | ||
insertSpaces = false, | ||
tabSize = 8, | ||
bool_test = true, | ||
int_test = 1, | ||
string_test = "string", | ||
}, | ||
textDocument = { | ||
uri = "file://", | ||
}, | ||
}, match.is_ref(f._handler), 1) | ||
end) | ||
|
||
it("sends format options", function() | ||
f.format { | ||
fargs = { "bool_test", "int_test=1", "string_test=string" }, | ||
} | ||
assert.stub(c.request).was_called(1) | ||
assert.stub(c.request).was_called_with("textDocument/formatting", { | ||
options = { | ||
insertSpaces = false, | ||
tabSize = 8, | ||
bool_test = true, | ||
int_test = 1, | ||
string_test = "string", | ||
}, | ||
textDocument = { | ||
uri = "file://", | ||
}, | ||
}, match.is_ref(f._handler), 1) | ||
end) | ||
|
||
it("overwrites default format options", function() | ||
f.setup { | ||
lua = { | ||
bool_test = true, | ||
int_test = 1, | ||
string_test = "string", | ||
}, | ||
} | ||
vim.bo.filetype = "lua" | ||
f.format { | ||
fargs = { "bool_test=false", "int_test=2", "string_test=another_string" }, | ||
} | ||
assert.stub(c.request).was_called(1) | ||
assert.stub(c.request).was_called_with("textDocument/formatting", { | ||
options = { | ||
insertSpaces = false, | ||
tabSize = 8, | ||
bool_test = false, | ||
int_test = 2, | ||
string_test = "another_string", | ||
}, | ||
textDocument = { | ||
uri = "file://", | ||
}, | ||
}, match.is_ref(f._handler), 1) | ||
end) | ||
|
||
it("does not overwrite changes", function() | ||
local apply_text_edits = spy.on(vim.lsp.util, "apply_text_edits") | ||
c.request = function(_, params, handler, bufnr) | ||
api.nvim_buf_get_var = function(_, var) | ||
if var == "format_changedtick" then | ||
return 9999 | ||
end | ||
return 1 | ||
end | ||
handler(nil, {}, { bufnr = bufnr, params = params }) | ||
end | ||
f.format {} | ||
assert.spy(apply_text_edits).was.called(0) | ||
end) | ||
|
||
it("does overwrite changes with force", function() | ||
local apply_text_edits = spy.on(vim.lsp.util, "apply_text_edits") | ||
c.request = function(_, params, handler, bufnr) | ||
api.nvim_buf_get_var = function(_, var) | ||
if var == "format_changedtick" then | ||
return 9999 | ||
end | ||
return 1 | ||
end | ||
handler(nil, {}, { bufnr = bufnr, params = params }) | ||
end | ||
f.format { fargs = { "force=true" } } | ||
assert.spy(apply_text_edits).was.called(1) | ||
end) | ||
|
||
it("does not overwrite when in insert mode", function() | ||
local apply_text_edits = spy.on(vim.lsp.util, "apply_text_edits") | ||
c.request = function(_, params, handler, bufnr) | ||
api.nvim_get_mode = function() | ||
return "insert" | ||
end | ||
handler(nil, {}, { bufnr = bufnr, params = params }) | ||
end | ||
f.format {} | ||
assert.spy(apply_text_edits).was.called(0) | ||
end) | ||
|
||
it("does overwrite when in insert mode with force", function() | ||
local apply_text_edits = spy.on(vim.lsp.util, "apply_text_edits") | ||
c.request = function(_, params, handler, bufnr) | ||
api.nvim_get_mode = function() | ||
return "insert" | ||
end | ||
handler(nil, {}, { bufnr = bufnr, params = params }) | ||
end | ||
f.format { fargs = { "force=true" } } | ||
assert.spy(apply_text_edits).was.called(1) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
set rtp-=~/.config/nvim | ||
set rtp-=~/.local/share/nvim/site | ||
set rtp+=. | ||
set noswapfile | ||
|
||
let $lsp_format = getcwd() | ||
let $specs = getcwd() .. "/specs" | ||
let $vendor = getcwd() .. "/vendor" | ||
|
||
set rtp+=$lsp_format,$specs | ||
set packpath=$vendor | ||
|
||
packloadall |