Skip to content

Commit

Permalink
4: Provides settings fallback using environment variables (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndCake authored Apr 4, 2022
1 parent 1ff0d33 commit 9f39429
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ The format for the `lsp.server` value is a comma-separated list for each file ty
<file type>=<executable with arguments where necessary>[=<initialization options passed to language server>][,...]
```

If you encounter an issue whereby the `lsp.server` settings configuration is auto-removed when you change any other configuration option,
you can use an environment variable called `MICRO_LSP` to define the same information. You can add a line such as the following to your shell profile (e.g. .bashrc):

```
export MICRO_LSP='python=pyls,go=gopls,typescript=deno lsp={"importMap":"import_map.json"},rust=rls'
```

The environment variable is used as a fallback if the `lsp.server` option is not defined.

Testing
-------

Expand Down
7 changes: 5 additions & 2 deletions main.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
VERSION = "0.4.1"

local micro = import("micro")
local config = import("micro/config")
local shell = import("micro/shell")
Expand Down Expand Up @@ -53,7 +55,8 @@ end
function startServers()
local wd, _ = os.Getwd()
rootUri = fmt.Sprintf("file://%s", wd)
local server = mysplit(config.GetGlobalOption("lsp.server") or '', ",")
local envFallback, _ = os.Getenv("MICRO_LSP")
local server = mysplit(config.GetGlobalOption("lsp.server") or envFallback or '', ",")
for i in pairs(server) do
local part = mysplit(server[i], "=")
local run = mysplit(part[2], "%s")
Expand All @@ -74,7 +77,7 @@ end

function init()
config.RegisterGlobalOption("lsp", "server", "")
config.RegisterGlobalOption("lsp", "formatOnSave", "")
config.RegisterGlobalOption("lsp", "formatOnSave", true)
config.MakeCommand("hover", hoverAction, config.NoComplete)
config.MakeCommand("definition", definitionAction, config.NoComplete)
config.MakeCommand("lspcompletion", completionAction, config.NoComplete)
Expand Down
10 changes: 5 additions & 5 deletions repo.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[{
"Name": "LSP",
"Name": "lsp",
"Description": "Generic LSP Client for Micro",
"Website": "https://github.com/user/plugin",
"Website": "https://github.com/AndCake/micro-plugin-lsp",
"Tags": ["lsp"],
"Versions": [
{
"Version": "1.0.0",
"Url": "https://github.com/user/plugin/archive/v1.0.0.zip",
"Version": "0.4.1",
"Url": "https://github.com/AndCake/micro-plugin-lsp/archive/v0.4.1.zip",
"Require": {
"micro": ">=1.0.3"
"micro": ">=2.0.10"
}
}
]
Expand Down

0 comments on commit 9f39429

Please sign in to comment.