From 25f65a5f7bd03ecc1796c12f6509d52381e8ee20 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Wed, 12 Aug 2020 21:40:20 -0400 Subject: [PATCH] LSP option and better LSP status --- cmd/micro/initlua.go | 10 ++++++++++ internal/buffer/buffer.go | 2 +- internal/buffer/settings.go | 6 ++++++ internal/config/runtime.go | 4 ++-- internal/config/settings.go | 1 + internal/lsp/install.go | 4 ++-- internal/lsp/server.go | 11 +++++++++-- runtime/plugins/status/status.lua | 12 ++++++++++++ 8 files changed, 43 insertions(+), 7 deletions(-) diff --git a/cmd/micro/initlua.go b/cmd/micro/initlua.go index 8b1dca82..a917e705 100644 --- a/cmd/micro/initlua.go +++ b/cmd/micro/initlua.go @@ -10,6 +10,7 @@ import ( "github.com/zyedidia/micro/v2/internal/buffer" "github.com/zyedidia/micro/v2/internal/config" "github.com/zyedidia/micro/v2/internal/display" + "github.com/zyedidia/micro/v2/internal/lsp" ulua "github.com/zyedidia/micro/v2/internal/lua" "github.com/zyedidia/micro/v2/internal/screen" "github.com/zyedidia/micro/v2/internal/shell" @@ -34,6 +35,8 @@ func LuaImport(pkg string) *lua.LTable { return luaImportMicroConfig() case "micro/util": return luaImportMicroUtil() + case "micro/lsp": + return luaImportMicroLsp() default: return ulua.Import(pkg) } @@ -153,3 +156,10 @@ func luaImportMicroUtil() *lua.LTable { return pkg } +func luaImportMicroLsp() *lua.LTable { + pkg := ulua.L.NewTable() + + ulua.L.SetField(pkg, "GetLanguage", luar.New(ulua.L, lsp.GetLanguage)) + + return pkg +} diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index 4b15d633..91927b3d 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -401,7 +401,7 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT OpenBuffers = append(OpenBuffers, b) if !found { - if btype == BTDefault { + if btype == BTDefault && b.Settings["lsp"].(bool) { b.lspInit() } } diff --git a/internal/buffer/settings.go b/internal/buffer/settings.go index e04d7061..0efa1a03 100644 --- a/internal/buffer/settings.go +++ b/internal/buffer/settings.go @@ -39,6 +39,12 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error { b.isModified = true } else if option == "readonly" && b.Type.Kind == BTDefault.Kind { b.Type.Readonly = nativeValue.(bool) + } else if option == "lsp" && b.Type.Kind == BTDefault.Kind { + if nativeValue.(bool) && !b.HasLSP() { + b.lspInit() + } else if b.HasLSP() { + b.Server.Shutdown() + } } return nil diff --git a/internal/config/runtime.go b/internal/config/runtime.go index 167347cb..68a6b538 100644 --- a/internal/config/runtime.go +++ b/internal/config/runtime.go @@ -1265,7 +1265,7 @@ func runtimePluginsStatusHelpStatusMd() (*asset, error) { return a, nil } -var _runtimePluginsStatusStatusLua = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x94\xc1\x6f\xdb\x20\x14\xc6\xef\xfe\x2b\x10\x27\x2c\xa5\xb4\x3b\xec\x52\x29\x87\xb4\x4b\x93\x6a\x55\x5b\xc5\x51\xb5\x2b\xb6\x9f\xe3\x27\x61\xb0\x00\x47\x6b\x0f\xfb\xdb\x27\xc0\x6e\x9d\xa4\x91\xbc\x69\xda\x91\x8f\xef\x7d\x7e\xfc\xf0\xe3\x65\xb9\xc9\xee\x9f\x1e\xc9\x9c\xd0\x2f\xfc\x8a\x5f\xd1\x24\x91\xba\x10\x92\x34\x58\x18\x4d\xe6\x04\x9b\x56\x1b\xc7\x68\x58\xd3\xb4\xdf\xcd\xbb\xaa\x02\x73\xbc\x7d\x19\xe5\x77\x57\xa1\x55\x85\xbb\x13\x57\x94\xdf\x5d\x75\xd7\x08\x85\x6f\x30\xf2\x0d\x12\x4d\x93\xa4\xea\x54\xe1\x50\x2b\x82\x0a\x1d\x4b\x13\x42\x48\x6c\x8e\x67\xe0\x32\x27\x5c\x67\xef\x55\xa5\xef\x14\xa3\x36\xac\x78\x6e\x84\x2a\x6a\x3a\xc5\x5a\x0b\x3b\xcd\xd8\x0a\xeb\x60\x92\x73\x5f\x68\x39\xc9\x28\x51\x81\x9d\xe4\xcc\x5f\xdd\x44\xa7\x8d\xd0\x26\x7c\xdc\xb6\xbd\x2f\xde\x06\x5f\x94\xe5\xa6\x53\x0e\x1b\xb8\x43\x09\x83\x8f\xce\x86\xfd\xcd\x76\x0d\xb2\x9d\x11\x5a\x83\x6c\x2f\xfb\x94\xa6\xa4\x69\x02\xaa\x1c\xdd\x52\x38\x15\xcb\x63\xb6\x01\xd7\x19\x45\x9c\xb6\xce\xa0\xda\xb1\xfc\xfa\xc1\x6f\x3f\x76\x0d\x4b\x8f\x0b\x3d\xb7\xf3\x75\x2b\x70\x8b\xc2\xe1\x1e\x6e\x3b\x63\xb5\x61\xa9\x57\x5e\xd0\x76\x42\xfe\x38\xcd\x0a\xc0\xce\x87\x65\xf8\x06\xa7\x45\x9e\xdd\x51\xcd\xf0\x1f\xf2\x9b\x18\x78\xa6\x52\xda\x76\x28\xc4\x8a\xe4\xd7\x6b\x61\x1f\xb2\x67\x96\x12\x57\x83\x0a\xf2\x28\x93\x6a\x45\x83\xe6\x33\x0e\xf4\xaa\xa2\xc7\xe7\x08\x7f\xf2\x38\x9b\x6f\x5f\x5b\xe0\xdf\x51\x95\xe4\xd7\xbc\x1f\x43\x7e\xb3\xf5\xb7\x7b\xf8\xb5\x38\x5b\xb6\x06\x29\x4f\x06\x30\xa8\xfd\xf5\x8f\xbc\x01\x8f\x1d\xb9\x7b\xc5\x4f\xe1\xa1\x35\xf6\x35\x23\x60\xfc\x1b\x10\xe2\xf8\xf2\x27\x14\xb7\xba\x69\x84\x2a\x19\xdd\xa1\xa3\x33\x42\x0d\xec\x2f\x5a\x61\x2c\xf8\xc5\xc5\x85\xc8\x73\xaf\x18\xa8\xfc\x7a\xbd\x5c\x7c\x1b\x35\x81\x55\x8c\x9b\x13\x85\xf2\xf0\x2c\x23\x4a\x7d\x4b\x7c\x6b\xb0\xc9\x5a\x51\x00\x8b\xbd\x7c\xe4\x0c\x58\xc7\x68\x3f\x80\x1f\xf2\xf5\xe3\x7f\x9e\xee\xd7\xff\x48\xd4\x77\xf2\xc7\x3c\x6d\xad\x8d\xfb\x87\x28\x7d\x13\x7f\x07\x32\x3c\x8f\x23\x92\xfd\xa3\xb1\x02\xb7\x92\x3a\x17\xf2\xa9\xf5\x36\x46\xfb\x67\xf4\xf3\xc1\x78\x5e\x64\xdb\x25\xf9\x7c\x38\xe2\x64\xfc\x0e\x00\x00\xff\xff\x54\x1d\xb1\xf6\xae\x06\x00\x00" +var _runtimePluginsStatusStatusLua = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x95\x4f\x6b\xdc\x3c\x10\xc6\xef\xfb\x29\x84\x4e\x36\x6c\x94\xbc\x87\xf7\x12\xd8\xc3\x26\xdd\x6c\x42\x43\x12\xe2\x25\x14\x4a\x0e\xb2\x3d\x5e\x0f\x91\x25\x21\xc9\xa1\xc9\xa1\x9f\xbd\x48\xb2\x77\xbd\xff\xc0\x2d\xa5\x37\x6b\xf4\xcc\xe3\x99\x9f\x3c\xf2\xcb\xe2\x39\xbb\x7b\x7c\x20\x33\x42\xff\x63\x17\xec\x82\x4e\x26\x42\x15\x5c\x90\x06\x0b\xa3\xc8\x8c\x60\xa3\x95\x71\x09\x0d\x6b\x9a\x76\xbb\x79\x5b\x55\x60\xf6\xb7\xcf\x63\x78\xa3\x2a\x94\xac\x70\x7d\xa0\x8a\xe1\x8d\xaa\x6e\x1b\x2e\xf1\x13\x06\xba\x3e\x44\xd3\xc9\xa4\x6a\x65\xe1\x50\x49\x82\x12\x5d\x92\x4e\x08\x21\xb1\x38\x96\x81\xcb\x1c\x77\xad\xbd\x93\x95\xba\x91\x09\xb5\x61\xc5\x72\xc3\x65\x51\xd3\x31\xd2\x9a\xdb\x71\x42\xcd\xad\x83\x51\xca\xf7\x42\x89\x51\x42\x81\x12\xec\x28\x65\xfe\xe1\x46\x2a\x6d\x84\x36\xe2\xe5\x56\x77\xba\x78\x1a\x6c\x5e\x96\xcf\xad\x74\xd8\xc0\x0d\x0a\xe8\x75\x74\xda\xef\x3f\xaf\x6e\x41\xe8\x29\xa1\x35\x08\x7d\xde\xb9\x34\x25\x4d\x27\x20\xcb\xc1\x29\x85\xae\x92\x3c\x7a\x1b\x70\xad\x91\xc4\x29\xeb\x0c\xca\x75\x92\x5f\xde\xfb\xed\x87\xb6\x49\xd2\xfd\x44\xcf\xed\x74\xde\x12\xdc\xbc\x70\xf8\x0e\xd7\xad\xb1\xca\x24\xa9\x8f\xbc\xa0\x6d\xb9\xf8\x76\xe8\x15\x80\x9d\x36\xcb\xf0\x13\x0e\x93\x3c\xbb\xbd\x9c\xfe\x3b\x64\x57\xd1\xf0\x44\xa6\xb0\xba\x4f\xc4\x8a\x48\xe5\x48\xee\xc1\x3b\x94\x6b\xfb\x9d\x7a\xd4\xaf\xc4\xd5\x20\x83\x62\x60\x4f\x4b\xb4\x3c\x17\x50\xd2\xb0\xe3\x4d\x3b\x8f\xfc\xf2\x96\xdb\xfb\xec\x29\x49\x8f\x27\x2a\xb9\x4d\x09\x0f\x71\x94\x84\xd5\x07\xd3\xb6\x3d\xe9\x4e\x33\x25\xea\x8d\xcc\xbc\x96\x2d\xc1\xdd\x73\xb9\x6e\xf9\x1a\x92\x61\xc9\x15\x0a\x70\x1f\x1a\xe8\xeb\x4e\x57\xea\xed\x78\x35\xad\xb4\xad\xf6\xef\x3c\xd2\x89\xcf\x13\x97\x77\xd2\x3a\x2e\x04\x94\x27\x1a\x12\xec\x5a\x35\x0d\x97\x25\x61\x8c\xd0\x90\x84\x7d\xca\xae\xe5\x86\x40\x55\xd1\xfd\x53\x0f\x73\x3f\x38\x89\x9c\xad\x3e\x34\xb0\xaf\x28\x4b\xf2\x73\xd6\x5d\x5a\xec\x6a\xe5\x67\x61\xb7\x8c\x88\xc6\xd6\x20\xc4\x01\xc0\x10\xed\x10\x0e\xb4\xe1\x63\xb2\x03\x75\x17\xf1\x77\xd6\xae\x34\xd6\x35\x25\x60\xfc\x8d\x19\xec\xd8\xe2\x07\x14\x5d\xcb\x09\x5d\xa3\xa3\x53\x42\x0d\xbc\x9f\x69\x6e\x2c\xf8\xc5\xd9\x19\xcf\x73\x1f\x31\x50\xf9\xf5\xed\x62\xfe\x65\x50\x04\x56\xd1\x6e\x46\x24\x8a\xdd\x5e\x06\x94\xba\x92\xd8\xca\x60\x93\x69\x5e\x40\x12\x6b\xd9\xfa\xf4\x58\x87\x68\xb7\xc0\x77\xf9\xfa\xcb\xf2\x34\xdd\xff\xff\x21\x51\x5f\xc9\x6f\xf3\xb4\xb5\x32\xee\x2f\xa2\xf4\x45\xfc\x19\xc8\xf0\x33\x19\x90\xec\xae\xd8\x25\xb8\xa5\x50\x39\x17\x8f\xda\xcb\x12\xda\xfd\x74\x8e\x0f\xdd\xd3\x3c\x5b\x2d\xc8\xf1\xe1\x88\x93\xf1\x2b\x00\x00\xff\xff\xa5\x47\xb2\xb8\xdc\x07\x00\x00" func runtimePluginsStatusStatusLuaBytes() ([]byte, error) { return bindataRead( @@ -5525,7 +5525,7 @@ func runtimeSyntaxRustHdr() (*asset, error) { return a, nil } -var _runtimeSyntaxRustYaml = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\x52\x4f\x4f\x1b\x3f\x10\xbd\xe7\x53\x98\x0d\x07\x20\x4a\x96\x2b\x7b\xf9\xe9\x27\x4a\xa5\x1e\x5a\xa4\x96\x43\xd4\xec\x0a\x79\xbd\x63\x62\xe1\x3f\xab\xf1\x38\x40\x34\x1f\xbe\xf2\x26\x21\x90\x20\x51\xa9\x39\x38\xde\xf9\xf7\xde\x3c\x3f\x6d\x2c\xd0\x4b\x0f\x95\xc0\x14\x69\x34\xea\x80\x40\x51\x35\x12\x42\x88\x9c\xf3\xd2\x41\x25\x8a\xba\x9e\x61\x3c\x2d\x46\x23\x4c\x16\xe2\x26\x3d\x16\x3a\x79\x45\x26\x78\xd1\x81\x36\xde\xe4\xeb\x90\x99\x0a\xd3\x81\x27\xa3\x0d\x60\x25\x0a\xed\xc5\x42\x4e\xd7\x97\xd3\xab\xfb\x66\x52\x0c\x15\xb9\xfb\x27\x44\xc0\x15\x74\xe2\x29\x60\x17\xb7\x8d\x91\x24\x81\x03\x4f\x03\x68\x7b\x26\xdb\x48\x28\x15\xb1\xb4\xe6\xc1\x07\xcd\x32\x72\x0b\x2a\x38\xe0\x36\x3c\x73\x8b\x20\x1f\x59\x05\x1f\x29\x9f\x64\x7c\x02\x56\x28\x09\xb8\x0b\x0c\x36\x02\x83\x4f\x8e\xe1\x99\x00\x3d\x6b\x99\x23\xda\x78\x69\x59\x7b\xd6\x01\xd9\x68\x36\xae\xb7\x6c\x3c\x5b\x20\xb6\x21\xf4\xec\xa4\xc2\xc0\x4e\x92\x5a\xb2\x0b\x1d\xbb\xb0\x02\x76\x89\x38\x68\x1d\x81\x82\xe6\xb0\x02\x44\xd3\x01\xf7\x68\x56\xdc\xa7\x96\xfb\x84\xc0\x08\x9a\x11\x28\xa1\xe7\x68\xd6\x10\x34\xe7\x7d\x8c\xe2\x08\x36\xdf\x31\x29\xe2\x98\x7a\x40\x26\x4c\xc0\x84\xd2\x10\x67\xfd\x87\x23\x68\x4e\x3e\x4a\x0d\xf9\xcf\xac\xa1\xe3\x14\x81\x57\x06\x29\x49\xcb\x4f\x4b\x40\xe0\xa7\xa5\xb1\xc0\x2f\x06\x6c\x77\x5e\xd7\xed\x5e\xce\x81\xf4\xab\x8c\x3d\x28\x23\x6d\x25\x8a\xac\xfc\x7d\x33\x39\xd9\x17\x5e\x67\xb5\xa4\xa7\x5d\xad\xda\x7e\xe7\xe2\xff\xa7\xbf\x9b\x7c\xbc\x7b\xa8\x1f\xc9\xb5\x80\x87\xe5\x33\x3f\x84\x37\xef\xb4\xb8\x9c\x5e\x35\x93\x77\x7c\xee\xf2\x6e\xb1\xbc\xf1\xc9\xc5\xf2\xd7\xb0\x7a\x2c\xef\x5e\x7a\x88\x25\x90\x9a\x6d\xa7\x6d\xbc\xb7\x05\x96\xd3\x75\xc6\x3d\x04\x8a\x84\xc6\x3f\x54\xdb\xc9\x22\x7b\x04\x07\x7f\x14\xc5\x6b\x0c\x7c\x77\x10\x89\x8f\xa6\x1f\xc8\xd5\xf5\x6c\x1f\x7d\xe3\xdf\xdd\xef\x2d\xd2\x46\xb6\xeb\xa5\xc4\x7d\xeb\xdf\xd2\xc1\xf1\xe4\x23\x46\xe3\xc9\x21\xba\x58\x34\xfb\xa1\x6e\x30\xfb\xd1\xb0\xb2\x3c\x9c\x74\xfa\xc9\x12\x14\xba\x50\x89\xe2\xec\xee\xf6\xcb\x2d\xcf\xe7\x73\xfe\xfa\x6d\xfe\xfd\xe6\xbc\xfa\xaf\xf8\x1c\xac\xae\x2f\x8e\x88\xd7\x17\xe5\x3f\x23\xee\x6c\x78\x84\x38\x3e\xa9\xeb\xc5\x31\x64\xf3\xa1\x54\x7f\x02\x00\x00\xff\xff\x3f\xf7\x58\xfe\xa4\x04\x00\x00" +var _runtimeSyntaxRustYaml = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\x53\x41\x6f\xf3\x36\x0c\xbd\xe7\x57\xe8\x73\xbe\x43\xd2\x20\x49\xd7\x16\xc5\xea\xcb\xb0\x75\x1d\xb0\xc3\x56\x60\xeb\x21\x58\x1c\x14\xb2\x4d\x35\x44\x65\xc9\xa0\xa8\xa4\x29\xf8\xe3\x07\x39\x49\xd3\x26\x05\x3a\x60\x3e\xd0\x12\x25\xf2\x3d\x3e\x8a\x06\x2d\xf0\xa6\x85\x5c\x51\x0c\xdc\xeb\xd5\xc0\x50\x71\xde\x53\x4a\xa9\x74\xe6\x74\x03\xb9\xca\x8a\x62\x42\xe1\x7b\xd6\xeb\x51\xb4\x10\xb6\xc7\x7d\x65\xa2\xab\x18\xbd\x53\x35\x18\x74\x98\x96\xdd\xc9\x58\x61\x0d\x8e\xd1\x20\x50\xae\x32\xe3\xd4\x5c\x8f\x5f\xcf\xc7\x37\x8f\x8b\x51\xd6\xdd\x48\xd1\x7f\x41\x00\x5a\x41\xad\xd6\x9e\xea\xb0\x0b\x0c\xac\x19\x1a\x70\xdc\x81\x96\x03\x5d\x06\x26\x5d\xb1\x68\x8b\x4f\xce\x1b\xd1\x41\x4a\xa8\x7c\x03\x52\xfa\x17\x29\x09\xf4\xb3\x54\xde\x05\x4e\x96\xd1\x45\x90\x8a\x34\x83\xd4\x5e\xea\x8d\x13\xb0\x01\x04\x5c\x6c\x04\x5e\x18\xc8\x89\xd1\xc9\x63\xd0\x69\x2b\xc6\x89\xf1\x24\x68\x04\x9b\xd6\x0a\x3a\xb1\xc0\x62\xbd\x6f\xa5\xd1\x15\x79\x69\x34\x57\x4b\x69\x7c\x2d\x8d\x5f\x81\x34\x91\xc5\x1b\x13\x80\xbd\x11\xbf\x02\x22\xac\x41\x5a\xc2\x95\xb4\xb1\x94\x36\x12\x08\x81\x11\x02\x8e\xe4\x24\xe0\x2b\x78\x23\xa9\x26\xac\x24\x80\x4d\x6b\x8a\x15\x4b\x88\x2d\x90\x30\x45\x10\x26\x8d\x2c\xa9\x07\x9d\xf1\x46\xa2\x0b\xda\x40\xfa\xe1\x2b\xd4\x12\x03\xc8\x0a\x89\xa3\xb6\xb2\x5e\x02\x81\xac\x97\x68\x41\x36\x08\xb6\x1e\x16\x45\x79\x90\xb4\x23\xfd\x26\x65\x0b\x15\x6a\x9b\xab\x2c\xa9\xff\xb8\x18\x7d\x3b\x5c\xbc\x4d\x8a\x69\xc7\xfb\xbb\xd5\x6e\xbf\x55\x7d\xfe\xf3\xf8\x9f\x45\x32\x8f\xe7\xe3\x9b\xc5\xe8\x03\xc4\x9f\xb1\x29\x81\x8e\xe3\x26\xae\x73\xef\xc2\x4f\xa3\x7e\xf1\xde\x82\x76\x9f\xc3\x0d\x3a\x1d\xba\xbe\x7c\x2c\xe7\x21\x49\x13\xa6\x77\x2e\x36\x61\xfa\x77\xa7\x5c\x98\x3e\x6c\x5a\x08\x53\xe0\x6a\xb2\x4b\xb6\x7d\xbe\x6f\xbc\x47\xa9\xda\x3d\xf7\xb3\xb4\x39\x72\x7d\x24\x16\xd1\x32\xba\x2e\x49\x50\xbc\xd4\x9c\x9e\x20\xb1\x5a\x23\x2f\x95\xf5\x6b\xa0\x4a\x07\x38\xc5\x1a\x94\xde\xdb\xd4\x4e\xc1\xd4\x26\x89\x9d\x1d\x0c\x50\xe2\x70\xf0\xa3\xfc\x70\x2d\x97\x17\x72\x7d\x35\x1c\x8a\xb9\xbc\x10\x73\x7d\xb5\x2d\xed\x58\xb7\xc0\x84\xee\x29\xdf\xf1\x51\x5b\xf0\x84\x90\x65\x6f\x3e\x70\xf5\x91\x27\x3c\x63\xdb\xd1\x28\x8a\xc9\xc1\xfb\x6e\x36\xf7\xdf\x7b\xa4\xed\x73\xb8\x5d\x6a\x3a\x84\xfe\x57\x3a\xd4\x1f\x7d\xc6\xa8\x3f\x3a\x46\x57\xf3\xc5\x21\x69\xd3\x0d\xf2\x49\xb2\xe9\xf4\x38\xd3\xf7\x2f\x8a\x60\x5f\xfb\x5c\x65\x83\x87\xfb\x5f\xef\x65\x36\x9b\xc9\x6f\xbf\xcf\xfe\xb8\x1b\xe6\x3f\x65\x5f\x83\x15\xc5\xd9\x09\xf1\xe2\x6c\xfa\xbf\x11\xf7\xe3\x75\x82\xd8\xff\x56\x14\xf3\x53\xc8\xc5\xa7\x52\xfd\x1b\x00\x00\xff\xff\x73\x64\x84\x65\x80\x05\x00\x00" func runtimeSyntaxRustYamlBytes() ([]byte, error) { return bindataRead( diff --git a/internal/config/settings.go b/internal/config/settings.go index efbc671a..884c76c9 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -272,6 +272,7 @@ var defaultCommonSettings = map[string]interface{}{ "ignorecase": false, "indentchar": " ", "keepautoindent": false, + "lsp": true, "matchbrace": true, "mkparents": false, "permbackup": false, diff --git a/internal/lsp/install.go b/internal/lsp/install.go index 33de2b89..37f38151 100644 --- a/internal/lsp/install.go +++ b/internal/lsp/install.go @@ -41,7 +41,7 @@ func LoadConfig(data []byte) (*Config, error) { return &conf, nil } -func (l *Language) Installed() bool { +func (l Language) Installed() bool { _, err := exec.LookPath(l.Command) if err != nil { return false @@ -50,7 +50,7 @@ func (l *Language) Installed() bool { return true } -func (l *Language) DoInstall(w io.Writer) error { +func (l Language) DoInstall(w io.Writer) error { if l.Installed() { return nil } diff --git a/internal/lsp/server.go b/internal/lsp/server.go index eeb947be..d5df791f 100644 --- a/internal/lsp/server.go +++ b/internal/lsp/server.go @@ -25,12 +25,18 @@ func init() { } func GetServer(l Language, dir string) *Server { - return activeServers[l.Command+"-"+dir] + s, ok := activeServers[l.Command+"-"+dir] + if ok && s.Active { + return s + } + return nil } func ShutdownAllServers() { for _, s := range activeServers { - s.Shutdown() + if s.Active { + s.Shutdown() + } } } @@ -178,6 +184,7 @@ func (s *Server) Initialize(directory string) { func (s *Server) Shutdown() { s.sendRequest(lsp.MethodShutdown, nil) s.sendNotification(lsp.MethodExit, nil) + s.Active = false } func (s *Server) receive() { diff --git a/runtime/plugins/status/status.lua b/runtime/plugins/status/status.lua index 49447e78..dc202fb0 100644 --- a/runtime/plugins/status/status.lua +++ b/runtime/plugins/status/status.lua @@ -34,9 +34,21 @@ function size(b) end function lsp(b) + if not b.Settings["lsp"] then + return "disabled" + end if b:HasLSP() then return "on" end + + local lsp = import("micro/lsp") + local l, ok = lsp.GetLanguage(b.Settings["filetype"]) + if not ok then + return "unsupported" + end + if not l:Installed() then + return l.Command .. " not installed" + end return "off" end