From 5cbf5be8ad4e334594d8178a18bd0190230e16c6 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Thu, 29 Aug 2024 22:51:39 +0200 Subject: [PATCH] refactor(hosts): Improve hosts structure --- handlers/aliases/{tree => ast}/aliases.go | 0 handlers/aliases/{tree => ast}/handler.go | 0 handlers/aliases/{tree => ast}/listener.go | 0 handlers/aliases/{tree => ast}/parser.go | 0 handlers/aliases/{tree => ast}/parser_test.go | 0 handlers/aliases/{tree => ast}/values.go | 0 .../hosts/{handlers => }/analyzer/analyzer.go | 0 .../hosts/{handlers => }/analyzer/double_ips.go | 0 .../{handlers => }/analyzer/double_ips_test.go | 2 +- .../{handlers => }/analyzer/handler_test.go | 2 +- .../hosts/{handlers => }/analyzer/resolve.go | 2 +- .../{handlers => }/analyzer/resolver_test.go | 2 +- handlers/hosts/{handlers => }/analyzer/values.go | 2 +- handlers/hosts/{handlers => }/ast/hosts.go | 0 handlers/hosts/{handlers => }/ast/listener.go | 16 ++++++++-------- handlers/hosts/{handlers => }/ast/parser.go | 6 +++--- handlers/hosts/{ => ast}/parser/Hosts.interp | 0 handlers/hosts/{ => ast}/parser/Hosts.tokens | 0 .../hosts/{ => ast}/parser/HostsLexer.interp | 0 .../hosts/{ => ast}/parser/HostsLexer.tokens | 0 .../{ => ast}/parser/hosts_base_listener.go | 0 handlers/hosts/{ => ast}/parser/hosts_lexer.go | 0 .../hosts/{ => ast}/parser/hosts_listener.go | 0 handlers/hosts/{ => ast}/parser/hosts_parser.go | 0 handlers/hosts/handlers/code-actions.go | 2 +- handlers/hosts/handlers/hover.go | 2 +- handlers/hosts/indexes/indexes.go | 4 +++- handlers/hosts/lsp/text-document-did-change.go | 2 +- handlers/hosts/lsp/text-document-did-open.go | 4 ++-- handlers/hosts/lsp/text-document-hover.go | 2 +- handlers/hosts/shared.go | 3 +-- 31 files changed, 26 insertions(+), 25 deletions(-) rename handlers/aliases/{tree => ast}/aliases.go (100%) rename handlers/aliases/{tree => ast}/handler.go (100%) rename handlers/aliases/{tree => ast}/listener.go (100%) rename handlers/aliases/{tree => ast}/parser.go (100%) rename handlers/aliases/{tree => ast}/parser_test.go (100%) rename handlers/aliases/{tree => ast}/values.go (100%) rename handlers/hosts/{handlers => }/analyzer/analyzer.go (100%) rename handlers/hosts/{handlers => }/analyzer/double_ips.go (100%) rename handlers/hosts/{handlers => }/analyzer/double_ips_test.go (97%) rename handlers/hosts/{handlers => }/analyzer/handler_test.go (98%) rename handlers/hosts/{handlers => }/analyzer/resolve.go (97%) rename handlers/hosts/{handlers => }/analyzer/resolver_test.go (98%) rename handlers/hosts/{handlers => }/analyzer/values.go (97%) rename handlers/hosts/{handlers => }/ast/hosts.go (100%) rename handlers/hosts/{handlers => }/ast/listener.go (85%) rename handlers/hosts/{handlers => }/ast/parser.go (91%) rename handlers/hosts/{ => ast}/parser/Hosts.interp (100%) rename handlers/hosts/{ => ast}/parser/Hosts.tokens (100%) rename handlers/hosts/{ => ast}/parser/HostsLexer.interp (100%) rename handlers/hosts/{ => ast}/parser/HostsLexer.tokens (100%) rename handlers/hosts/{ => ast}/parser/hosts_base_listener.go (100%) rename handlers/hosts/{ => ast}/parser/hosts_lexer.go (100%) rename handlers/hosts/{ => ast}/parser/hosts_listener.go (100%) rename handlers/hosts/{ => ast}/parser/hosts_parser.go (100%) diff --git a/handlers/aliases/tree/aliases.go b/handlers/aliases/ast/aliases.go similarity index 100% rename from handlers/aliases/tree/aliases.go rename to handlers/aliases/ast/aliases.go diff --git a/handlers/aliases/tree/handler.go b/handlers/aliases/ast/handler.go similarity index 100% rename from handlers/aliases/tree/handler.go rename to handlers/aliases/ast/handler.go diff --git a/handlers/aliases/tree/listener.go b/handlers/aliases/ast/listener.go similarity index 100% rename from handlers/aliases/tree/listener.go rename to handlers/aliases/ast/listener.go diff --git a/handlers/aliases/tree/parser.go b/handlers/aliases/ast/parser.go similarity index 100% rename from handlers/aliases/tree/parser.go rename to handlers/aliases/ast/parser.go diff --git a/handlers/aliases/tree/parser_test.go b/handlers/aliases/ast/parser_test.go similarity index 100% rename from handlers/aliases/tree/parser_test.go rename to handlers/aliases/ast/parser_test.go diff --git a/handlers/aliases/tree/values.go b/handlers/aliases/ast/values.go similarity index 100% rename from handlers/aliases/tree/values.go rename to handlers/aliases/ast/values.go diff --git a/handlers/hosts/handlers/analyzer/analyzer.go b/handlers/hosts/analyzer/analyzer.go similarity index 100% rename from handlers/hosts/handlers/analyzer/analyzer.go rename to handlers/hosts/analyzer/analyzer.go diff --git a/handlers/hosts/handlers/analyzer/double_ips.go b/handlers/hosts/analyzer/double_ips.go similarity index 100% rename from handlers/hosts/handlers/analyzer/double_ips.go rename to handlers/hosts/analyzer/double_ips.go diff --git a/handlers/hosts/handlers/analyzer/double_ips_test.go b/handlers/hosts/analyzer/double_ips_test.go similarity index 97% rename from handlers/hosts/handlers/analyzer/double_ips_test.go rename to handlers/hosts/analyzer/double_ips_test.go index dda6c3f..b095018 100644 --- a/handlers/hosts/handlers/analyzer/double_ips_test.go +++ b/handlers/hosts/analyzer/double_ips_test.go @@ -2,7 +2,7 @@ package analyzer import ( "config-lsp/handlers/hosts" - "config-lsp/handlers/hosts/handlers/ast" + "config-lsp/handlers/hosts/ast" "config-lsp/handlers/hosts/indexes" "config-lsp/handlers/hosts/shared" "config-lsp/utils" diff --git a/handlers/hosts/handlers/analyzer/handler_test.go b/handlers/hosts/analyzer/handler_test.go similarity index 98% rename from handlers/hosts/handlers/analyzer/handler_test.go rename to handlers/hosts/analyzer/handler_test.go index b4c674e..38e34c1 100644 --- a/handlers/hosts/handlers/analyzer/handler_test.go +++ b/handlers/hosts/analyzer/handler_test.go @@ -1,7 +1,7 @@ package analyzer import ( - "config-lsp/handlers/hosts/handlers/ast" + "config-lsp/handlers/hosts/ast" "config-lsp/utils" "net" "testing" diff --git a/handlers/hosts/handlers/analyzer/resolve.go b/handlers/hosts/analyzer/resolve.go similarity index 97% rename from handlers/hosts/handlers/analyzer/resolve.go rename to handlers/hosts/analyzer/resolve.go index b060700..846af98 100644 --- a/handlers/hosts/handlers/analyzer/resolve.go +++ b/handlers/hosts/analyzer/resolve.go @@ -3,7 +3,7 @@ package analyzer import ( "config-lsp/common" "config-lsp/handlers/hosts" - "config-lsp/handlers/hosts/handlers/ast" + "config-lsp/handlers/hosts/ast" "config-lsp/handlers/hosts/indexes" "config-lsp/handlers/hosts/shared" "config-lsp/utils" diff --git a/handlers/hosts/handlers/analyzer/resolver_test.go b/handlers/hosts/analyzer/resolver_test.go similarity index 98% rename from handlers/hosts/handlers/analyzer/resolver_test.go rename to handlers/hosts/analyzer/resolver_test.go index b0a2a4b..df720e7 100644 --- a/handlers/hosts/handlers/analyzer/resolver_test.go +++ b/handlers/hosts/analyzer/resolver_test.go @@ -1,7 +1,7 @@ package analyzer import ( - "config-lsp/handlers/hosts/handlers/ast" + "config-lsp/handlers/hosts/ast" "config-lsp/utils" "testing" ) diff --git a/handlers/hosts/handlers/analyzer/values.go b/handlers/hosts/analyzer/values.go similarity index 97% rename from handlers/hosts/handlers/analyzer/values.go rename to handlers/hosts/analyzer/values.go index ed27721..e6da88e 100644 --- a/handlers/hosts/handlers/analyzer/values.go +++ b/handlers/hosts/analyzer/values.go @@ -3,8 +3,8 @@ package analyzer import ( "config-lsp/common" docvalues "config-lsp/doc-values" + "config-lsp/handlers/hosts/ast" "config-lsp/handlers/hosts/fields" - "config-lsp/handlers/hosts/handlers/ast" "config-lsp/utils" "errors" ) diff --git a/handlers/hosts/handlers/ast/hosts.go b/handlers/hosts/ast/hosts.go similarity index 100% rename from handlers/hosts/handlers/ast/hosts.go rename to handlers/hosts/ast/hosts.go diff --git a/handlers/hosts/handlers/ast/listener.go b/handlers/hosts/ast/listener.go similarity index 85% rename from handlers/hosts/handlers/ast/listener.go rename to handlers/hosts/ast/listener.go index c5f2782..dd26bb6 100644 --- a/handlers/hosts/handlers/ast/listener.go +++ b/handlers/hosts/ast/listener.go @@ -3,7 +3,7 @@ package ast import ( "config-lsp/common" docvalues "config-lsp/doc-values" - "config-lsp/handlers/hosts/parser" + parser2 "config-lsp/handlers/hosts/ast/parser" "net" "github.com/antlr4-go/antlr/v4" @@ -14,18 +14,18 @@ type hostsListenerContext struct { } type hostsParserListener struct { - *parser.BaseHostsListener + *parser2.BaseHostsListener Parser *HostsParser Errors []common.LSPError hostsContext hostsListenerContext } -func (s *hostsParserListener) EnterComment(ctx *parser.CommentContext) { +func (s *hostsParserListener) EnterComment(ctx *parser2.CommentContext) { line := uint32(s.hostsContext.line) s.Parser.CommentLines[line] = struct{}{} } -func (s *hostsParserListener) EnterEntry(ctx *parser.EntryContext) { +func (s *hostsParserListener) EnterEntry(ctx *parser2.EntryContext) { location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext) location.ChangeBothLines(s.hostsContext.line) @@ -34,7 +34,7 @@ func (s *hostsParserListener) EnterEntry(ctx *parser.EntryContext) { } } -func (s *hostsParserListener) EnterIpAddress(ctx *parser.IpAddressContext) { +func (s *hostsParserListener) EnterIpAddress(ctx *parser2.IpAddressContext) { location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext) location.ChangeBothLines(s.hostsContext.line) @@ -65,7 +65,7 @@ func (s *hostsParserListener) EnterIpAddress(ctx *parser.IpAddressContext) { } } -func (s *hostsParserListener) EnterHostname(ctx *parser.HostnameContext) { +func (s *hostsParserListener) EnterHostname(ctx *parser2.HostnameContext) { location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext) location.ChangeBothLines(s.hostsContext.line) @@ -79,7 +79,7 @@ func (s *hostsParserListener) EnterHostname(ctx *parser.HostnameContext) { s.Parser.Tree.Entries[location.Start.Line] = entry } -func (s *hostsParserListener) EnterAliases(ctx *parser.AliasesContext) { +func (s *hostsParserListener) EnterAliases(ctx *parser2.AliasesContext) { location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext) location.ChangeBothLines(s.hostsContext.line) @@ -90,7 +90,7 @@ func (s *hostsParserListener) EnterAliases(ctx *parser.AliasesContext) { entry.Aliases = aliases } -func (s *hostsParserListener) EnterAlias(ctx *parser.AliasContext) { +func (s *hostsParserListener) EnterAlias(ctx *parser2.AliasContext) { location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext) location.ChangeBothLines(s.hostsContext.line) diff --git a/handlers/hosts/handlers/ast/parser.go b/handlers/hosts/ast/parser.go similarity index 91% rename from handlers/hosts/handlers/ast/parser.go rename to handlers/hosts/ast/parser.go index 03f3c92..bfdcf82 100644 --- a/handlers/hosts/handlers/ast/parser.go +++ b/handlers/hosts/ast/parser.go @@ -2,7 +2,7 @@ package ast import ( "config-lsp/common" - "config-lsp/handlers/hosts/parser" + parser2 "config-lsp/handlers/hosts/ast/parser" "config-lsp/utils" "regexp" @@ -26,7 +26,7 @@ func (p *HostsParser) parseStatement( stream := antlr.NewInputStream(input) errorListener := createErrorListener(line) - lexer := parser.NewHostsLexer(stream) + lexer := parser2.NewHostsLexer(stream) lexer.RemoveErrorListeners() lexer.AddErrorListener(&errorListener) @@ -34,7 +34,7 @@ func (p *HostsParser) parseStatement( errorListener = createErrorListener(line) tokenStream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel) - antlrParser := parser.NewHostsParser(tokenStream) + antlrParser := parser2.NewHostsParser(tokenStream) antlrParser.RemoveErrorListeners() antlrParser.AddErrorListener(&errorListener) diff --git a/handlers/hosts/parser/Hosts.interp b/handlers/hosts/ast/parser/Hosts.interp similarity index 100% rename from handlers/hosts/parser/Hosts.interp rename to handlers/hosts/ast/parser/Hosts.interp diff --git a/handlers/hosts/parser/Hosts.tokens b/handlers/hosts/ast/parser/Hosts.tokens similarity index 100% rename from handlers/hosts/parser/Hosts.tokens rename to handlers/hosts/ast/parser/Hosts.tokens diff --git a/handlers/hosts/parser/HostsLexer.interp b/handlers/hosts/ast/parser/HostsLexer.interp similarity index 100% rename from handlers/hosts/parser/HostsLexer.interp rename to handlers/hosts/ast/parser/HostsLexer.interp diff --git a/handlers/hosts/parser/HostsLexer.tokens b/handlers/hosts/ast/parser/HostsLexer.tokens similarity index 100% rename from handlers/hosts/parser/HostsLexer.tokens rename to handlers/hosts/ast/parser/HostsLexer.tokens diff --git a/handlers/hosts/parser/hosts_base_listener.go b/handlers/hosts/ast/parser/hosts_base_listener.go similarity index 100% rename from handlers/hosts/parser/hosts_base_listener.go rename to handlers/hosts/ast/parser/hosts_base_listener.go diff --git a/handlers/hosts/parser/hosts_lexer.go b/handlers/hosts/ast/parser/hosts_lexer.go similarity index 100% rename from handlers/hosts/parser/hosts_lexer.go rename to handlers/hosts/ast/parser/hosts_lexer.go diff --git a/handlers/hosts/parser/hosts_listener.go b/handlers/hosts/ast/parser/hosts_listener.go similarity index 100% rename from handlers/hosts/parser/hosts_listener.go rename to handlers/hosts/ast/parser/hosts_listener.go diff --git a/handlers/hosts/parser/hosts_parser.go b/handlers/hosts/ast/parser/hosts_parser.go similarity index 100% rename from handlers/hosts/parser/hosts_parser.go rename to handlers/hosts/ast/parser/hosts_parser.go diff --git a/handlers/hosts/handlers/code-actions.go b/handlers/hosts/handlers/code-actions.go index b2f6bc4..7618226 100644 --- a/handlers/hosts/handlers/code-actions.go +++ b/handlers/hosts/handlers/code-actions.go @@ -1,7 +1,7 @@ package handlers import ( - "config-lsp/handlers/hosts/handlers/ast" + "config-lsp/handlers/hosts/ast" "config-lsp/utils" "fmt" "strings" diff --git a/handlers/hosts/handlers/hover.go b/handlers/hosts/handlers/hover.go index 2361408..50cc9cd 100644 --- a/handlers/hosts/handlers/hover.go +++ b/handlers/hosts/handlers/hover.go @@ -2,7 +2,7 @@ package handlers import ( "config-lsp/handlers/hosts" - "config-lsp/handlers/hosts/handlers/ast" + "config-lsp/handlers/hosts/ast" "fmt" ) diff --git a/handlers/hosts/indexes/indexes.go b/handlers/hosts/indexes/indexes.go index 512a724..886619a 100644 --- a/handlers/hosts/indexes/indexes.go +++ b/handlers/hosts/indexes/indexes.go @@ -1,6 +1,8 @@ package indexes -import "config-lsp/handlers/hosts/shared" +import ( + "config-lsp/handlers/hosts/shared" +) type HostsIndexes struct { Resolver *Resolver diff --git a/handlers/hosts/lsp/text-document-did-change.go b/handlers/hosts/lsp/text-document-did-change.go index e6ba5e6..0b4bb34 100644 --- a/handlers/hosts/lsp/text-document-did-change.go +++ b/handlers/hosts/lsp/text-document-did-change.go @@ -3,7 +3,7 @@ package lsp import ( "config-lsp/common" "config-lsp/handlers/hosts" - "config-lsp/handlers/hosts/handlers/analyzer" + "config-lsp/handlers/hosts/analyzer" "config-lsp/utils" "github.com/tliron/glsp" diff --git a/handlers/hosts/lsp/text-document-did-open.go b/handlers/hosts/lsp/text-document-did-open.go index a9886cf..6e17715 100644 --- a/handlers/hosts/lsp/text-document-did-open.go +++ b/handlers/hosts/lsp/text-document-did-open.go @@ -3,8 +3,8 @@ package lsp import ( "config-lsp/common" "config-lsp/handlers/hosts" - "config-lsp/handlers/hosts/handlers/analyzer" - "config-lsp/handlers/hosts/handlers/ast" + "config-lsp/handlers/hosts/analyzer" + "config-lsp/handlers/hosts/ast" "config-lsp/handlers/hosts/indexes" "config-lsp/utils" diff --git a/handlers/hosts/lsp/text-document-hover.go b/handlers/hosts/lsp/text-document-hover.go index fd76edb..1c6484e 100644 --- a/handlers/hosts/lsp/text-document-hover.go +++ b/handlers/hosts/lsp/text-document-hover.go @@ -2,9 +2,9 @@ package lsp import ( "config-lsp/handlers/hosts" + "config-lsp/handlers/hosts/ast" "config-lsp/handlers/hosts/fields" "config-lsp/handlers/hosts/handlers" - "config-lsp/handlers/hosts/handlers/ast" "strings" "github.com/tliron/glsp" diff --git a/handlers/hosts/shared.go b/handlers/hosts/shared.go index d17e04c..e71cbbb 100644 --- a/handlers/hosts/shared.go +++ b/handlers/hosts/shared.go @@ -1,9 +1,8 @@ package hosts import ( - "config-lsp/handlers/hosts/handlers/ast" + "config-lsp/handlers/hosts/ast" "config-lsp/handlers/hosts/indexes" - protocol "github.com/tliron/glsp/protocol_3_16" )