-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
248 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
return { | ||
_all = { | ||
coverage = false, | ||
lpath = "lua/?.lua;lua/?/init.lua", | ||
lua = "~/.luarocks/bin/nlua", | ||
}, | ||
default = { | ||
verbose = true, | ||
}, | ||
tests = { | ||
verbose = true, | ||
}, | ||
} |
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,28 @@ | ||
name: Tests | ||
on: | ||
pull_request: ~ | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
name: Run tests | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
neovim_version: ["nightly", "stable", "v0.9.0"] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install luau-lsp | ||
run: | | ||
wget https://github.com/JohnnyMorganz/luau-lsp/releases/download/1.32.1/luau-lsp-linux-arm64.zip | ||
unzip luau-lsp*.zip | ||
sudo mv luau-lsp /usr/local/bin/luau-lsp | ||
- name: Run tests | ||
uses: nvim-neorocks/nvim-busted-action@v1 | ||
with: | ||
nvim_version: ${{ matrix.neovim_version }} |
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 +1,4 @@ | ||
docs/tags | ||
/luarocks | ||
/lua_modules | ||
/.luarocks |
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,15 @@ | ||
rockspec_format = "3.0" | ||
package = "luau-lsp.nvim" | ||
version = "scm-1" | ||
|
||
source = { | ||
url = "git+https://github.com/lopi-py/luau-lsp.nvim.git", | ||
} | ||
|
||
dependencies = { | ||
"plenary.nvim", | ||
} | ||
|
||
test_dependencies = { | ||
"nlua", | ||
} |
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,21 @@ | ||
local command = require "luau-lsp.command" | ||
local compat = require "luau-lsp.compat" | ||
|
||
describe("command executor", function() | ||
it("should provide completion for regenerate_sourcemap", function() | ||
local cwd = compat.uv.cwd() | ||
assert(cwd) | ||
|
||
compat.uv.chdir(cwd .. "/spec/roblox-project") | ||
|
||
local items1 = command.complete("reg", "LuauLsp reg") | ||
local items2 = command.complete("", "LuauLsp regenerate_sourcemap ") | ||
local items3 = command.complete("serv", "LuauLsp regenerate_sourcemap serv") | ||
|
||
compat.uv.chdir(cwd) | ||
|
||
assert.same({ "regenerate_sourcemap" }, items1) | ||
assert.same({ "dev.project.json", "serve.project.json" }, items2) | ||
assert.same({ "serve.project.json" }, items3) | ||
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,6 @@ | ||
{ | ||
"name": "dev", | ||
"tree": { | ||
"$className": "DataModel" | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"name": "server", | ||
"tree": { | ||
"$className": "DataModel" | ||
} | ||
} |
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,138 @@ | ||
local compat = require "luau-lsp.compat" | ||
local config = require "luau-lsp.config" | ||
local server = require "luau-lsp.server" | ||
|
||
local buffers = {} | ||
|
||
local function create_luau_buffer() | ||
local bufnr = vim.api.nvim_create_buf(true, false) | ||
vim.bo[bufnr].filetype = "luau" | ||
|
||
server.start(bufnr) | ||
table.insert(buffers, bufnr) | ||
|
||
vim.api.nvim_set_current_buf(bufnr) | ||
|
||
return bufnr | ||
end | ||
|
||
local function wait_for_client() | ||
vim.wait(5000, function() | ||
local clients = compat.get_clients { name = "luau-lsp" } | ||
return clients[1] ~= nil | ||
end) | ||
|
||
local clients = compat.get_clients { name = "luau-lsp" } | ||
assert.same(1, #clients) | ||
|
||
return clients[1] | ||
end | ||
|
||
describe("luau-lsp server", function() | ||
---@diagnostic disable-next-line: duplicate-set-field | ||
vim.notify = function() end | ||
|
||
after_each(function() | ||
local client = wait_for_client() | ||
client.stop(true) | ||
vim.wait(100) | ||
|
||
for _, bufnr in ipairs(buffers) do | ||
if vim.api.nvim_buf_is_valid(bufnr) then | ||
vim.api.nvim_buf_delete(bufnr, {}) | ||
end | ||
end | ||
end) | ||
|
||
it("should attach a client to a luau buffer", function() | ||
local bufnr = create_luau_buffer() | ||
local client = wait_for_client() | ||
assert.same({ bufnr }, vim.lsp.get_buffers_by_client_id(client.id)) | ||
end) | ||
|
||
it("should resue the same client for multiple buffers", function() | ||
local first = create_luau_buffer() | ||
local second = create_luau_buffer() | ||
local third = create_luau_buffer() | ||
|
||
-- try to start the server for the same buffer many times | ||
server.start(first) | ||
server.start(first) | ||
server.start(third) | ||
|
||
local client = wait_for_client() | ||
assert.same({ first, second, third }, vim.lsp.get_buffers_by_client_id(client.id)) | ||
end) | ||
|
||
it("should handle roblox configuration", function() | ||
config.config { | ||
platform = { | ||
type = "standard", | ||
}, | ||
sourcemap = { | ||
enabled = false, | ||
}, | ||
} | ||
|
||
local notify = stub(vim, "notify") | ||
local bufnr = create_luau_buffer() | ||
local client = wait_for_client() | ||
|
||
assert.stub(notify).called(0) | ||
assert.same({ "luau-lsp", "lsp", "--no-flags-enabled" }, client.config.cmd) | ||
|
||
client.stop(true) | ||
vim.wait(100) | ||
|
||
config.config { | ||
platform = { | ||
type = "roblox", | ||
}, | ||
sourcemap = { | ||
enabled = true, | ||
}, | ||
} | ||
|
||
server.start(bufnr) | ||
client = wait_for_client() | ||
|
||
assert.stub(notify).was.called_with( | ||
"[luau-lsp.nvim]: Unable to find project file `default.project.json`", | ||
vim.log.levels.ERROR, | ||
{ title = "luau-lsp.nvim" } | ||
) | ||
assert.match("globalTypes.PluginSecurity.d.luau", client.config.cmd[4]) | ||
assert.match("api%-docs.json", client.config.cmd[5]) | ||
end) | ||
|
||
it("should respect user settings", function() | ||
config.config { | ||
server = { | ||
settings = { | ||
["luau-lsp"] = { | ||
testSetting = { | ||
testField = "testing", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
create_luau_buffer() | ||
local client = wait_for_client() | ||
|
||
assert.same({ | ||
["luau-lsp"] = { | ||
platform = { | ||
type = "roblox", | ||
}, | ||
sourcemap = { | ||
enabled = true, | ||
}, | ||
testSetting = { | ||
testField = "testing", | ||
}, | ||
}, | ||
}, compat.get_client_settings(client)) | ||
end) | ||
end) |