Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvements #24

Merged
merged 9 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Check version in code matches flake version
shell: bash
run: |
if ! [ $(grep '// CI:CD-VERSION$' server/root-handler/handler.go | cut -d'"' -f 2) = $(grep '# CI:CD-VERSION$' flake.nix | cut -d'"' -f 2) ];
if ! [ $(grep '// CI:CD-VERSION$' server/root-handler/common.go | cut -d'"' -f 2) = $(grep '# CI:CD-VERSION$' flake.nix | cut -d'"' -f 2) ];
then
echo "Version mismatch between code and flake"
exit 1
Expand Down
53 changes: 43 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,52 @@ You are welcome to request any config file, as far as it's fairly well known.

## Installation

### VS Code Extension

[Install the extension from the marketplace](https://marketplace.visualstudio.com/items?itemName=myzel394.config-lsp)

Alternatively, you can also manually install the extension:

1. Download the latest extension version from the [release page](https://github.com/Myzel394/config-lsp/releases) - You can find the extension under the "assets" section. The filename ends with `.vsix`
2. Open VS Code
3. Open the extensions sidebar
4. In the top bar, click on the three dots and select "Install from VSIX..."
5. Select the just downloaded `.vsix` file
6. You may need to restart VS Code
7. Enjoy!

### Manual installation

To use `config-lsp` in any other editor, you'll need to install it manually.
Don't worry, it's easy!

#### Installing the latest Binary

##### Brew

```sh
brew install myzel394/formulae/config-lsp
```

##### Manual Binary

Download the latest binary from the [releases page](https://github.com/Myzel394/config-lsp/releases) and put it in your PATH.

Follow the instructions for your editor below.
##### Compiling

You can either compile the binary using go:

```sh
go build -o config-lsp
```

or build it using Nix:

```sh
nix flake build
```

### Neovim installation
#### Neovim installation

Using [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) you can add `config-lsp` by adding the following to your `lsp.lua` (filename might differ):

Expand All @@ -57,14 +98,6 @@ end
lspconfig.config_lsp.setup {}
`````

### VS Code installation

The VS Code extension is currently in development. An official extension will be released soon.

However, at the moment you can also compile the extension yourself and run it in development mode.

**Do not create an extension and publish it yourself. Contribute to the official extension instead.**

## Supporting config-lsp

You can either contribute to the project, [see CONTRIBUTING.md](CONTRIBUTING.md), or you can sponsor me via [GitHub Sponsors](https://github.com/sponsors/Myzel394) or via [crypto currencies](https://github.com/Myzel394/contact-me?tab=readme-ov-file#donations).
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"aarch64-windows"
] (system:
let
version = "0.1.1"; # CI:CD-VERSION
version = "0.1.2"; # CI:CD-VERSION
pkgs = import nixpkgs {
inherit system;
overlays = [
Expand Down
9 changes: 9 additions & 0 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
roothandler "config-lsp/root-handler"
"fmt"
"os"

"github.com/tliron/commonlog"

Expand All @@ -11,6 +13,13 @@ import (
)

func main() {
if len(os.Args) > 1 && (os.Args[1] == "--version" || os.Args[1] == "version") {
fmt.Println(roothandler.Version)

os.Exit(0)
return
}

// This increases logging verbosity (optional)
commonlog.Configure(1, nil)

Expand Down
5 changes: 5 additions & 0 deletions server/root-handler/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package roothandler

// The comment below at the end of the line is required for the CI:CD to work.
// Do not remove it
var Version = "0.1.2" // CI:CD-VERSION
35 changes: 17 additions & 18 deletions server/root-handler/handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package roothandler

import (
"config-lsp/root-handler/lsp"
"config-lsp/root-handler/shared"
"github.com/tliron/glsp"
protocol "github.com/tliron/glsp/protocol_3_16"

Expand All @@ -9,32 +11,29 @@ import (

const lsName = "config-lsp"

// The comment below at the end of the line is required for the CI:CD to work.
// Do not remove it
var version = "0.1.1" // CI:CD-VERSION

var lspHandler protocol.Handler

// The root handler which handles all the LSP requests and then forwards them to the appropriate handler
func SetUpRootHandler() {
rootHandler = NewRootHandler()
shared.Handler = shared.NewRootHandler()

lspHandler = protocol.Handler{
Initialize: initialize,
Initialized: initialized,
Shutdown: shutdown,
SetTrace: setTrace,
TextDocumentDidOpen: TextDocumentDidOpen,
TextDocumentDidChange: TextDocumentDidChange,
TextDocumentCompletion: TextDocumentCompletion,
TextDocumentHover: TextDocumentHover,
TextDocumentDidClose: TextDocumentDidClose,
TextDocumentCodeAction: TextDocumentCodeAction,
TextDocumentDefinition: TextDocumentDefinition,
WorkspaceExecuteCommand: WorkspaceExecuteCommand,
TextDocumentRename: TextDocumentRename,
TextDocumentPrepareRename: TextDocumentPrepareRename,
TextDocumentSignatureHelp: TextDocumentSignatureHelp,
TextDocumentRangeFormatting: TextDocumentRangeFormattingFunc,
TextDocumentDidOpen: lsp.TextDocumentDidOpen,
TextDocumentDidChange: lsp.TextDocumentDidChange,
TextDocumentCompletion: lsp.TextDocumentCompletion,
TextDocumentHover: lsp.TextDocumentHover,
TextDocumentDidClose: lsp.TextDocumentDidClose,
TextDocumentCodeAction: lsp.TextDocumentCodeAction,
TextDocumentDefinition: lsp.TextDocumentDefinition,
WorkspaceExecuteCommand: lsp.WorkspaceExecuteCommand,
TextDocumentRename: lsp.TextDocumentRename,
TextDocumentPrepareRename: lsp.TextDocumentPrepareRename,
TextDocumentSignatureHelp: lsp.TextDocumentSignatureHelp,
TextDocumentRangeFormatting: lsp.TextDocumentRangeFormattingFunc,
}

server := server.NewServer(&lspHandler, lsName, false)
Expand Down Expand Up @@ -72,7 +71,7 @@ func initialize(context *glsp.Context, params *protocol.InitializeParams) (any,
Capabilities: capabilities,
ServerInfo: &protocol.InitializeResultServerInfo{
Name: lsName,
Version: &version,
Version: &Version,
},
}, nil
}
Expand Down
149 changes: 0 additions & 149 deletions server/root-handler/lsp-utils.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
package roothandler
package lsp

import (
aliases "config-lsp/handlers/aliases/lsp"
hosts "config-lsp/handlers/hosts/lsp"
sshconfig "config-lsp/handlers/ssh_config/lsp"
wireguard "config-lsp/handlers/wireguard/lsp"
"config-lsp/root-handler/shared"
utils "config-lsp/root-handler/utils"

"github.com/tliron/glsp"
protocol "github.com/tliron/glsp/protocol_3_16"
)

func TextDocumentCodeAction(context *glsp.Context, params *protocol.CodeActionParams) (any, error) {
language := rootHandler.GetLanguageForDocument(params.TextDocument.URI)
language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI)

if language == nil {
showParseError(
context,
params.TextDocument.URI,
undetectableError,
)

return nil, nil
return utils.FetchAddLanguageActions(params.TextDocument.URI)
}

switch *language {
case LanguageFstab:
case shared.LanguageFstab:
return nil, nil
case LanguageHosts:
case shared.LanguageHosts:
return hosts.TextDocumentCodeAction(context, params)
case LanguageSSHDConfig:
case shared.LanguageSSHDConfig:
return nil, nil
case LanguageSSHConfig:
case shared.LanguageSSHConfig:
return sshconfig.TextDocumentCodeAction(context, params)
case LanguageWireguard:
case shared.LanguageWireguard:
return wireguard.TextDocumentCodeAction(context, params)
case LanguageAliases:
case shared.LanguageAliases:
return aliases.TextDocumentCodeAction(context, params)
}

Expand Down
Loading