Repository: neovim/neovim
File: runtime/lua/vim/lsp.lua (Lua)

Code before:
lsp.rpc_response_error = lsp.rpc.rpc_response_error

lsp._resolve_to_request = {
  ['codeAction/resolve'] = 'textDocument/codeAction',
  ['codeLens/resolve'] = 'textDocument/codeLens',
  ['documentLink/resolve'] = 'textDocument/documentLink',
  ['inlayHint/resolve'] = 'textDocument/inlayHint',
}

-- TODO improve handling of scratch buffers with LSP attached.

--- Called by the client when trying to call a method that's not
--- supported in any of the servers registered for the current buffer.
---@param method (vim.lsp.protocol.Method.ClientToServer) name of the method
function lsp._unsupported_method(method)
  local msg = string.format(
    'vim.lsp: method %q is not supported by any server activated for this buffer',
    method
  )
  log.warn(msg)
  return msg
end

---@param workspace_folders string|lsp.WorkspaceFolder[]|fun(bufnr: integer, on_dir:fun(root_dir?:string))?
---@return lsp.WorkspaceFolder[]?
function lsp._get_workspace_folders(workspace_folders)
  if type(workspace_folders) == 'table' then
    return workspace_folders
  elseif type(workspace_folders) == 'string' then
    return {
      {
        uri = vim.uri_from_fname(workspace_folders),
        name = workspace_folders,
      },
    }
  elseif type(workspace_folders) == 'function' then
    local name ---@type string
    workspace_folders(0, function(root_dir)
      name = root_dir
    end)
    return name
      and {
        {
          uri = vim.uri_from_fname(name),
          name = name,
        },
      }
  end
end

local wait_result_reason = { [-1] = 'timeout', [-2] = 'interrupted', [-3] = 'error' }

Review comment (suggestion):
might be a useful hint to name this parameter `root_dir`
```suggestion
function lsp._get_workspace_folders(root_dir)
```

Code after:
lsp.rpc_response_error = lsp.rpc.rpc_response_error

lsp._resolve_to_request = {
  ['codeAction/resolve'] = 'textDocument/codeAction',
  ['codeLens/resolve'] = 'textDocument/codeLens',
  ['documentLink/resolve'] = 'textDocument/documentLink',
  ['inlayHint/resolve'] = 'textDocument/inlayHint',
}

-- TODO improve handling of scratch buffers with LSP attached.

--- Called by the client when trying to call a method that's not
--- supported in any of the servers registered for the current buffer.
---@param method (vim.lsp.protocol.Method.ClientToServer) name of the method
function lsp._unsupported_method(method)
  local msg = string.format(
    'vim.lsp: method %q is not supported by any server activated for this buffer',
    method
  )
  log.warn(msg)
  return msg
end

---@param workspace_folders string|lsp.WorkspaceFolder[]|fun(bufnr: integer, on_dir:fun(root_dir?:string))?
---@return lsp.WorkspaceFolder[]?
function lsp._get_workspace_folders(workspace_folders)
  if type(workspace_folders) == 'table' then
    return workspace_folders
  elseif type(workspace_folders) == 'string' then
    return {
      {
        uri = vim.uri_from_fname(workspace_folders),
        name = workspace_folders,
      },
    }
  elseif type(workspace_folders) == 'function' then
    local name = lsp.client._resolve_root_dir(1000, 0, workspace_folders)
    return name
      and {
        {
          uri = vim.uri_from_fname(name),
          name = name,
        },
      }
  end
end

local wait_result_reason = { [-1] = 'timeout', [-2] = 'interrupted', [-3] = 'error' }

local format_line_ending = {
  ['unix'] = '\n',