Skip to content

Commit

Permalink
feat: add apex_ls (chipsalliance#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamboman authored Jun 3, 2022
1 parent d19ea3c commit f5f6538
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ require("nvim-lsp-installer").setup({
| AWK | `awk_ls` |
| Angular | `angularls` |
| Ansible | `ansiblels` |
| Apex | `apex_ls` |
| Arduino [(docs!!!)][arduino] | `arduino_language_server` |
| Assembly (GAS/NASM, GO) | `asm_lsp` |
| Astro | `astro` |
Expand Down
1 change: 1 addition & 0 deletions lua/nvim-lsp-installer/_generated/filetype_map.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-- stylua: ignore start
return {
OpenFOAM = { "foam_ls" },
apexcode = { "apex_ls" },
arduino = { "arduino_language_server" },
asm = { "asm_lsp" },
aspnetcorerazor = { "tailwindcss" },
Expand Down
3 changes: 3 additions & 0 deletions lua/nvim-lsp-installer/_generated/metadata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ return {
ansiblels = {
filetypes = { "yaml.ansible" }
},
apex_ls = {
filetypes = { "apexcode" }
},
arduino_language_server = {
filetypes = { "arduino" }
},
Expand Down
2 changes: 2 additions & 0 deletions lua/nvim-lsp-installer/core/functional/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ _.concat = list.concat
_.zip_table = list.zip_table
_.nth = list.nth
_.head = list.head
_.length = list.length

-- relation
local relation = require "nvim-lsp-installer.core.functional.relation"
Expand Down Expand Up @@ -62,6 +63,7 @@ local string = require "nvim-lsp-installer.core.functional.string"
_.matches = string.matches
_.format = string.format
_.split = string.split
_.gsub = string.gsub

-- table
local tbl = require "nvim-lsp-installer.core.functional.table"
Expand Down
5 changes: 5 additions & 0 deletions lua/nvim-lsp-installer/core/functional/list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,9 @@ end, 2)

_.head = _.nth(1)

---@param value string|any[]
_.length = function(value)
return #value
end

return _
7 changes: 7 additions & 0 deletions lua/nvim-lsp-installer/core/functional/string.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ _.split = fun.curryN(function(sep, str)
return vim.split(str, sep)
end, 2)

---@param pattern string
---@param repl string|function|table
---@param str string
_.gsub = fun.curryN(function(pattern, repl, str)
return string.gsub(str, pattern, repl)
end, 3)

return _
2 changes: 1 addition & 1 deletion lua/nvim-lsp-installer/core/managers/cargo/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local M = {}

---@async
---@param crate string
---@return Result @of [Crate]
---@return Result @of Crate
function M.fetch_crate(crate)
return fetch(("https://crates.io/api/v1/crates/%s"):format(crate)):map_catching(vim.json.decode)
end
Expand Down
5 changes: 3 additions & 2 deletions lua/nvim-lsp-installer/core/managers/github/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ end

---@async
---@param repo string @The GitHub repo ("username/repo").
---@return Result @of GitHubRelease[]
function M.fetch_releases(repo)
log.fmt_trace("Fetching GitHub releases for repo=%s", repo)
local path = ("repos/%s/releases"):format(repo)
Expand Down Expand Up @@ -87,7 +88,7 @@ end

---@async
---@param repo string @The GitHub repo ("username/repo").
---@return Result @of [GitHubTag[]]
---@return Result @of GitHubTag[]
function M.fetch_tags(repo)
local path = ("repos/%s/tags"):format(repo)
return api_call(path):map_err(function()
Expand All @@ -97,7 +98,7 @@ end

---@async
---@param repo string @The GitHub repo ("username/repo").
---@return Result @of [GitHubTag]
---@return Result @of GitHubTag
function M.fetch_latest_tag(repo)
return M.fetch_tags(repo):map_catching(function(tags)
if vim.tbl_count(tags) == 0 then
Expand Down
44 changes: 44 additions & 0 deletions lua/nvim-lsp-installer/servers/apex_ls/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
local server = require "nvim-lsp-installer.server"
local github = require "nvim-lsp-installer.core.managers.github"
local github_client = require "nvim-lsp-installer.core.managers.github.client"
local git = require "nvim-lsp-installer.core.managers.git"
local Optional = require "nvim-lsp-installer.core.optional"
local path = require "nvim-lsp-installer.core.path"
local _ = require "nvim-lsp-installer.core.functional"

return function(name, root_dir)
local JAR_FILE = "apex-jorje-lsp.jar"

return server.Server:new {
name = name,
root_dir = root_dir,
homepage = "https://github.com/forcedotcom/salesforcedx-vscode",
languages = { "apex" },
---@async
---@param ctx InstallContext
installer = function(ctx)
local repo = "forcedotcom/salesforcedx-vscode"

-- See https://github.com/forcedotcom/salesforcedx-vscode/issues/4184#issuecomment-1146052086
---@type GitHubRelease
local release = github_client
.fetch_releases(repo)
:map(_.find_first(_.prop_satisfies(_.compose(_.gt(0), _.length), "assets")))
:map(Optional.of_nilable)
:get_or_throw() -- Result unwrap
:or_else_throw "Failed to find release with assets." -- Optional unwrap

github.unzip_release_file({
version = Optional.of(release.tag_name),
asset_file = _.compose(_.format "salesforcedx-vscode-apex-%s.vsix", _.gsub("^v", "")),
repo = repo,
}).with_receipt()

ctx.fs:rename(path.concat { "extension", "out", JAR_FILE }, JAR_FILE)
ctx.fs:rmrf "extension"
end,
default_options = {
apex_jar_path = path.concat { root_dir, JAR_FILE },
},
}
end
1 change: 1 addition & 0 deletions lua/nvim-lsp-installer/servers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ local INSTALL_DIRS = {
local CORE_SERVERS = _.set_of {
"angularls",
"ansiblels",
"apex_ls",
"arduino_language_server",
"asm_lsp",
"astro",
Expand Down
9 changes: 9 additions & 0 deletions tests/core/functional/list_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,13 @@ describe("functional: list", function()
assert.is_nil(_.nth(0, { "value" }))
assert.equals("", _.nth(0, "abc"))
end)

it("should get length", function()
assert.equals(0, _.length {})
assert.equals(0, _.length { nil })
assert.equals(0, _.length { obj = "doesnt count" })
assert.equals(0, _.length "")
assert.equals(1, _.length { "" })
assert.equals(4, _.length "fire")
end)
end)
4 changes: 4 additions & 0 deletions tests/core/functional/string_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ describe("functional: string", function()
assert.same({ "This", "is", "a", "sentence" }, _.split("%s", "This is a sentence"))
assert.same({ "This", "is", "a", "sentence" }, _.split("|", "This|is|a|sentence"))
end)

it("should gsub strings", function()
assert.same("predator", _.gsub("^apex%s*", "", "apex predator"))
end)
end)

0 comments on commit f5f6538

Please sign in to comment.