mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
current stand
This commit is contained in:
parent
431d63d440
commit
dfba267b40
116
flake.lock
generated
Normal file
116
flake.lock
generated
Normal file
@ -0,0 +1,116 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1694529238,
|
||||
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"gomod2nix": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1722589758,
|
||||
"narHash": "sha256-sbbA8b6Q2vB/t/r1znHawoXLysCyD4L/6n6/RykiSnA=",
|
||||
"owner": "tweag",
|
||||
"repo": "gomod2nix",
|
||||
"rev": "4e08ca09253ef996bd4c03afa383b23e35fe28a1",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "tweag",
|
||||
"repo": "gomod2nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1723637854,
|
||||
"narHash": "sha256-med8+5DSWa2UnOqtdICndjDAEjxr5D7zaIiK4pn0Q7c=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "c3aa7b8938b17aebd2deecf7be0636000d62a2b9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"gomod2nix": "gomod2nix",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"utils": "utils"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems_2": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"utils": {
|
||||
"inputs": {
|
||||
"systems": "systems_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
39
flake.nix
Normal file
39
flake.nix
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
description = "Build config-lsp";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
||||
gomod2nix = {
|
||||
url = "github:tweag/gomod2nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
inputs.utils.follows = "utils";
|
||||
};
|
||||
utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, utils, gomod2nix }:
|
||||
utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [
|
||||
(final: prev: {
|
||||
go = prev.go_1_22;
|
||||
buildGoModule = prev.buildGo122Module;
|
||||
})
|
||||
gomod2nix.overlays.default
|
||||
];
|
||||
};
|
||||
in {
|
||||
defaultPackage = pkgs.buildGoModule {
|
||||
pname = "github.com/Myzel394/config-lsp";
|
||||
version = "v0.0.1";
|
||||
src = ./.;
|
||||
vendorHash = "sha256-gv73FvSEhNKPnlyfTgSxum1T2T711+xrhJFmKMuCAQs=";
|
||||
};
|
||||
devShell = pkgs.mkShell {
|
||||
buildInputs = [ pkgs.go_1_22 ];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
@ -84,3 +84,7 @@ func (p wireguardSection) analyzeInterfaceSection() []protocol.Diagnostic {
|
||||
|
||||
return diagnostics
|
||||
}
|
||||
|
||||
func (p wireguardParser) analyzeAllowedIPIsInRange() []protocol.Diagnostic {
|
||||
|
||||
}
|
||||
|
@ -214,10 +214,6 @@ Remove the iptables rule that forwards packets on the WireGuard interface
|
||||
`,
|
||||
Value: docvalues.StringValue{},
|
||||
},
|
||||
"PreSharedKey": {
|
||||
Documentation: "Optionally defines a pre-shared key for the peer, used to authenticate the connection. This is not necessary, but strongly recommended for security.",
|
||||
Value: docvalues.StringValue{},
|
||||
},
|
||||
}
|
||||
|
||||
var interfaceAllowedDuplicateFields = map[string]struct{}{
|
||||
@ -309,10 +305,12 @@ Oocal NAT-ed node to remote public node
|
||||
`,
|
||||
Value: docvalues.PositiveNumberValue(),
|
||||
},
|
||||
"PreSharedKey": {
|
||||
"PresharedKey": {
|
||||
Documentation: "Optionally defines a pre-shared key for the peer, used to authenticate the connection. This is not necessary, but strongly recommended for security.",
|
||||
Value: docvalues.StringValue{},
|
||||
},
|
||||
}
|
||||
|
||||
var peerAllowedDuplicateFields = map[string]struct{}{}
|
||||
var peerAllowedDuplicateFields = map[string]struct{}{
|
||||
"AllowedIPs": {},
|
||||
}
|
||||
|
@ -19,30 +19,22 @@ type characterLocation struct {
|
||||
}
|
||||
|
||||
type wireguardParser struct {
|
||||
Sections []wireguardSection
|
||||
GlobalSection *wireguardSection
|
||||
// <key = name>: if nil then does not belong to a section
|
||||
Sections map[string]wireguardSection
|
||||
// Used to identify where not to show diagnostics
|
||||
CommentLines map[uint32]struct{}
|
||||
}
|
||||
|
||||
func (p *wireguardParser) clear() {
|
||||
p.Sections = []wireguardSection{}
|
||||
p.Sections = map[string]wireguardSection{}
|
||||
p.CommentLines = map[uint32]struct{}{}
|
||||
}
|
||||
|
||||
func (p wireguardParser) hasInterfaceSection() bool {
|
||||
for _, section := range p.Sections {
|
||||
if section.Name != nil && *section.Name == "Interface" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (p wireguardParser) getRootCompletionsForEmptyLine() []protocol.CompletionItem {
|
||||
completions := []protocol.CompletionItem{}
|
||||
|
||||
if !p.hasInterfaceSection() {
|
||||
if _, found := p.Sections["Interface"]; !found {
|
||||
completions = append(completions, headerInterfaceEnum.ToCompletionItem())
|
||||
}
|
||||
|
||||
@ -134,13 +126,14 @@ func (p *wireguardParser) parseFromString(input string) []common.ParseError {
|
||||
lastLine = *lastPropertyLine
|
||||
}
|
||||
|
||||
section := createWireguardSection(
|
||||
name, section := createWireguardSection(
|
||||
currentLineNumber,
|
||||
lastLine,
|
||||
line,
|
||||
collectedProperties,
|
||||
)
|
||||
p.Sections = append(p.Sections, section)
|
||||
|
||||
p.Sections[name] = section
|
||||
|
||||
// Reset
|
||||
collectedProperties = wireguardProperties{}
|
||||
@ -149,18 +142,13 @@ func (p *wireguardParser) parseFromString(input string) []common.ParseError {
|
||||
}
|
||||
|
||||
if len(collectedProperties) > 0 {
|
||||
p.Sections = append(p.Sections, wireguardSection{
|
||||
p.GlobalSection = &wireguardSection{
|
||||
StartLine: *earliestPropertyLine,
|
||||
EndLine: *lastPropertyLine,
|
||||
Name: nil,
|
||||
Properties: collectedProperties,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Since we parse the content from bottom to top,
|
||||
// we need to reverse the order
|
||||
slices.Reverse(p.Sections)
|
||||
|
||||
return errors
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"config-lsp/utils"
|
||||
"fmt"
|
||||
"maps"
|
||||
"math"
|
||||
"regexp"
|
||||
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
@ -25,8 +26,6 @@ func (e propertyNotFullyTypedError) Error() string {
|
||||
type wireguardSection struct {
|
||||
StartLine uint32
|
||||
EndLine uint32
|
||||
// nil = do not belong to a section
|
||||
Name *string
|
||||
Properties wireguardProperties
|
||||
}
|
||||
|
||||
@ -34,7 +33,7 @@ func (s wireguardSection) String() string {
|
||||
var name string
|
||||
|
||||
if s.Name == nil {
|
||||
name = "//<nil>//"
|
||||
name = "<nil>"
|
||||
} else {
|
||||
name = *s.Name
|
||||
}
|
||||
@ -177,12 +176,14 @@ func (p wireguardSection) getCompletionsForPropertyLine(
|
||||
|
||||
var validHeaderPattern = regexp.MustCompile(`^\s*\[(?P<header>.+?)\]\s*$`)
|
||||
|
||||
// Create a new create section
|
||||
// Return (<name>, <new section>)
|
||||
func createWireguardSection(
|
||||
startLine uint32,
|
||||
endLine uint32,
|
||||
headerLine string,
|
||||
props wireguardProperties,
|
||||
) wireguardSection {
|
||||
) (string, wireguardSection) {
|
||||
match := validHeaderPattern.FindStringSubmatch(headerLine)
|
||||
|
||||
var header string
|
||||
@ -194,10 +195,9 @@ func createWireguardSection(
|
||||
header = match[1]
|
||||
}
|
||||
|
||||
return wireguardSection{
|
||||
return header, wireguardSection{
|
||||
StartLine: startLine,
|
||||
EndLine: endLine,
|
||||
Name: &header,
|
||||
Properties: props,
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
vim.lsp.start {
|
||||
name = "config-lsp",
|
||||
cmd = { "./bin/config-lsp" },
|
||||
cmd = { "./result/bin/config-lsp" },
|
||||
root_dir = vim.fn.getcwd(),
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user