-
Notifications
You must be signed in to change notification settings - Fork 295
feat(mini.files): make file system actions LSP aware #2340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
428db7c
4427d83
7e132b1
893bf39
6f4b4d3
ebd9465
b46bf46
b58419f
6465b0e
7375255
7034afe
7e794e5
2eeed42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| require('something') |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| local server_name = _G.server_name or 'file-methods-lsp' | ||
| _G.lsp_requests = _G.lsp_requests or {} | ||
| _G.lsp_notifications = _G.lsp_notifications or {} | ||
|
|
||
| _G.workspace_edits_response = _G.workspace_edits_response | ||
| or { range = { start = { line = 0, character = 0 }, ['end'] = { line = 0, character = 0 } }, newText = '' } | ||
|
|
||
| _G.filter_configs = _G.filter_configs or { filters = { { pattern = { glob = '**' } } } } | ||
| local fc = _G.filter_configs | ||
| local file_operations_config = _G.file_operations_config | ||
| or { willCreate = fc, willDelete = fc, willRename = fc, didCreate = fc, didDelete = fc, didRename = fc } | ||
|
|
||
| local capabilities = { workspace = { fileOperations = file_operations_config } } | ||
|
|
||
| _G.did_callback = _G.did_callback or function(params, dispatchers) end | ||
|
|
||
| local make_will_request = function(method) | ||
| return function(params) | ||
| _G.lsp_requests[server_name] = _G.lsp_requests[server_name] or {} | ||
| table.insert(_G.lsp_requests[server_name], { method, params }) | ||
| local path = vim.fn.fnamemodify('tests/dir-files/lsp-files/main.lua', ':p') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea of separate LSP mocks is that they should not depend on module specific test files. Can this be be generalized (like by using
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A global variable could be used for configuring this. If
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whatever makes it not assume that it runs in a 'mini.files' test in the most concise way. |
||
| local uri = vim.uri_from_fname(path) | ||
| return { changes = { [uri] = _G.workspace_edits_response } } | ||
| end | ||
| end | ||
|
|
||
| local make_did_notification = function(method) | ||
| return function(params, dispatchers) | ||
| _G.lsp_notifications[server_name] = _G.lsp_notifications[server_name] or {} | ||
| table.insert(_G.lsp_notifications[server_name], { method, params }) | ||
| _G.did_callback(params, dispatchers) | ||
| end | ||
| end | ||
|
|
||
| local requests = { | ||
| initialize = function(_) return { capabilities = capabilities } end, | ||
| shutdown = function(_) return nil end, | ||
|
|
||
| ['workspace/willCreateFiles'] = make_will_request('workspace/willCreateFiles'), | ||
| ['workspace/willRenameFiles'] = make_will_request('workspace/willRenameFiles'), | ||
| ['workspace/willDeleteFiles'] = make_will_request('workspace/willDeleteFiles'), | ||
| } | ||
|
|
||
| local notifications = { | ||
| ['workspace/didCreateFiles'] = make_did_notification('workspace/didCreateFiles'), | ||
| ['workspace/didRenameFiles'] = make_did_notification('workspace/didRenameFiles'), | ||
| ['workspace/didDeleteFiles'] = make_did_notification('workspace/didDeleteFiles'), | ||
| } | ||
|
|
||
| local cmd = function(dispatchers) | ||
| local is_closing, request_id = false, 0 | ||
|
|
||
| return { | ||
| request = function(method, params, callback) | ||
| local method_impl = requests[method] | ||
| if method_impl ~= nil then callback(nil, method_impl(params)) end | ||
| request_id = request_id + 1 | ||
| return true, request_id | ||
| end, | ||
| notify = function(method, params) | ||
| local method_impl = notifications[method] | ||
| if method_impl ~= nil then method_impl(params, dispatchers) end | ||
| return true | ||
| end, | ||
| is_closing = function() return is_closing end, | ||
| terminate = function() is_closing = true end, | ||
| } | ||
| end | ||
|
|
||
| -- Start server and attach to current buffer | ||
| return vim.lsp.start({ name = server_name, cmd = cmd, root_dir = vim.fn.getcwd() }) | ||
Uh oh!
There was an error while loading. Please reload this page.