Skip to content

Commit

Permalink
Merge pull request #118 from mattn/fix-typos
Browse files Browse the repository at this point in the history
Fix typos & cosmetic changes
  • Loading branch information
mattn authored Dec 20, 2023
2 parents a9a7705 + 5cbd35e commit 088ad8a
Show file tree
Hide file tree
Showing 32 changed files with 336 additions and 340 deletions.
133 changes: 66 additions & 67 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ type NodeType int
const (
TypeItem NodeType = iota
TypeMultiKeyword
TypeMemberIdentifer
TypeMemberIdentifier
TypeAliased
TypeIdentifer
TypeIdentifier
TypeOperator
TypeComparison
TypeParenthesis
TypeParenthesisInner
TypeFunctionLiteral
TypeQuery
TypeStatement
TypeIdentiferList
TypeIdentifierList
TypeSwitchCase
TypeNull
)

type RenderOptions struct {
LowerCase bool
IdentiferQuated bool
LowerCase bool
IdentifierQuated bool
}

type Node interface {
Expand Down Expand Up @@ -108,92 +108,92 @@ func (mk *MultiKeyword) Pos() token.Pos { return findFrom(mk) }
func (mk *MultiKeyword) End() token.Pos { return findTo(mk) }
func (mk *MultiKeyword) GetKeywords() []Node { return mk.Keywords }

type MemberIdentifer struct {
type MemberIdentifier struct {
Toks []Node
Parent Node
ParentTok *SQLToken
ParentIdent *Identifer
ParentIdent *Identifier
Child Node
ChildTok *SQLToken
ChildIdent *Identifer
ChildIdent *Identifier
}

func NewMemberIdentiferParent(nodes []Node, parent Node) *MemberIdentifer {
memberIdentifier := &MemberIdentifer{Toks: nodes}
func NewMemberIdentifierParent(nodes []Node, parent Node) *MemberIdentifier {
memberIdentifier := &MemberIdentifier{Toks: nodes}
memberIdentifier.setParent(parent)
if v, ok := parent.(*Identifer); ok {
if v, ok := parent.(*Identifier); ok {
memberIdentifier.ParentIdent = v
}
return memberIdentifier
}

func NewMemberIdentifer(nodes []Node, parent Node, child Node) *MemberIdentifer {
memberIdentifier := &MemberIdentifer{Toks: nodes}
func NewMemberIdentifier(nodes []Node, parent Node, child Node) *MemberIdentifier {
memberIdentifier := &MemberIdentifier{Toks: nodes}
memberIdentifier.setParent(parent)
if v, ok := parent.(*Identifer); ok {
if v, ok := parent.(*Identifier); ok {
memberIdentifier.ParentIdent = v
}
memberIdentifier.setChild(child)
if v, ok := child.(*Identifer); ok {
if v, ok := child.(*Identifier); ok {
memberIdentifier.ChildIdent = v
}
return memberIdentifier
}

func (mi *MemberIdentifer) String() string {
func (mi *MemberIdentifier) String() string {
var strs []string
for _, t := range mi.Toks {
strs = append(strs, t.String())
}
return strings.Join(strs, "")
}
func (mi *MemberIdentifer) Render(opts *RenderOptions) string {
func (mi *MemberIdentifier) Render(opts *RenderOptions) string {
var strs []string
for _, t := range mi.Toks {
strs = append(strs, t.Render(opts))
}
return strings.Join(strs, "")
}
func (mi *MemberIdentifer) Type() NodeType { return TypeMemberIdentifer }
func (mi *MemberIdentifer) GetTokens() []Node { return mi.Toks }
func (mi *MemberIdentifer) SetTokens(toks []Node) { mi.Toks = toks }
func (mi *MemberIdentifer) Pos() token.Pos { return findFrom(mi) }
func (mi *MemberIdentifer) End() token.Pos { return findTo(mi) }
func (mi *MemberIdentifer) setParent(node Node) {
func (mi *MemberIdentifier) Type() NodeType { return TypeMemberIdentifier }
func (mi *MemberIdentifier) GetTokens() []Node { return mi.Toks }
func (mi *MemberIdentifier) SetTokens(toks []Node) { mi.Toks = toks }
func (mi *MemberIdentifier) Pos() token.Pos { return findFrom(mi) }
func (mi *MemberIdentifier) End() token.Pos { return findTo(mi) }
func (mi *MemberIdentifier) setParent(node Node) {
mi.Parent = node
tok, ok := node.(Token)
if ok {
mi.ParentTok = tok.GetToken()
}
}
func (mi *MemberIdentifer) setChild(node Node) {
func (mi *MemberIdentifier) setChild(node Node) {
mi.Child = node
tok, ok := node.(Token)
if ok {
mi.ChildTok = tok.GetToken()
}
}
func (mi *MemberIdentifer) GetParent() Node {
func (mi *MemberIdentifier) GetParent() Node {
if mi.Parent == nil {
return &Null{}
}
return mi.Parent
}
func (mi *MemberIdentifer) GetParentIdent() *Identifer {
func (mi *MemberIdentifier) GetParentIdent() *Identifier {
if mi.ParentIdent == nil {
return &Identifer{}
return &Identifier{}
}
return mi.ParentIdent
}
func (mi *MemberIdentifer) GetChild() Node {
func (mi *MemberIdentifier) GetChild() Node {
if mi.Child == nil {
return &Null{}
}
return mi.Child
}
func (mi *MemberIdentifer) GetChildIdent() *Identifer {
func (mi *MemberIdentifier) GetChildIdent() *Identifier {
if mi.ChildIdent == nil {
return &Identifer{}
return &Identifier{}
}
return mi.ChildIdent
}
Expand Down Expand Up @@ -225,31 +225,31 @@ func (a *Aliased) GetTokens() []Node { return a.Toks }
func (a *Aliased) SetTokens(toks []Node) { a.Toks = toks }
func (a *Aliased) Pos() token.Pos { return findFrom(a) }
func (a *Aliased) End() token.Pos { return findTo(a) }
func (a *Aliased) GetAliasedNameIdent() *Identifer {
if v, ok := a.AliasedName.(*Identifer); ok {
func (a *Aliased) GetAliasedNameIdent() *Identifier {
if v, ok := a.AliasedName.(*Identifier); ok {
return v
}
return &Identifer{}
return &Identifier{}
}

type Identifer struct {
type Identifier struct {
Tok *SQLToken
}

func (i *Identifer) Type() NodeType { return TypeIdentifer }
func (i *Identifer) String() string { return i.Tok.String() }
func (i *Identifer) Render(opts *RenderOptions) string {
func (i *Identifier) Type() NodeType { return TypeIdentifier }
func (i *Identifier) String() string { return i.Tok.String() }
func (i *Identifier) Render(opts *RenderOptions) string {
tmpOpts := &RenderOptions{
LowerCase: false,
IdentiferQuated: opts.IdentiferQuated,
LowerCase: false,
IdentifierQuated: opts.IdentifierQuated,
}
return i.Tok.Render(tmpOpts)
}
func (i *Identifer) NoQuateString() string { return i.Tok.NoQuateString() }
func (i *Identifer) GetToken() *SQLToken { return i.Tok }
func (i *Identifer) Pos() token.Pos { return i.Tok.From }
func (i *Identifer) End() token.Pos { return i.Tok.To }
func (i *Identifer) IsWildcard() bool { return i.Tok.MatchKind(token.Mult) }
func (i *Identifier) NoQuateString() string { return i.Tok.NoQuateString() }
func (i *Identifier) GetToken() *SQLToken { return i.Tok }
func (i *Identifier) Pos() token.Pos { return i.Tok.From }
func (i *Identifier) End() token.Pos { return i.Tok.To }
func (i *Identifier) IsWildcard() bool { return i.Tok.MatchKind(token.Mult) }

type Operator struct {
Toks []Node
Expand Down Expand Up @@ -412,32 +412,32 @@ func (s *Statement) SetTokens(toks []Node) { s.Toks = toks }
func (s *Statement) Pos() token.Pos { return findFrom(s) }
func (s *Statement) End() token.Pos { return findTo(s) }

type IdentiferList struct {
Toks []Node
Identifers []Node
Commas []Node
type IdentifierList struct {
Toks []Node
Identifiers []Node
Commas []Node
}

func (il *IdentiferList) String() string {
func (il *IdentifierList) String() string {
return joinString(il.Toks)
}
func (il *IdentiferList) Render(opts *RenderOptions) string {
func (il *IdentifierList) Render(opts *RenderOptions) string {
return joinRender(il.Toks, opts)
}
func (il *IdentiferList) Type() NodeType { return TypeIdentiferList }
func (il *IdentiferList) GetTokens() []Node { return il.Toks }
func (il *IdentiferList) SetTokens(toks []Node) { il.Toks = toks }
func (il *IdentiferList) Pos() token.Pos { return findFrom(il) }
func (il *IdentiferList) End() token.Pos { return findTo(il) }
func (il *IdentiferList) GetIdentifers() []Node { return il.Identifers }
func (il *IdentiferList) GetIndex(pos token.Pos) int {
func (il *IdentifierList) Type() NodeType { return TypeIdentifierList }
func (il *IdentifierList) GetTokens() []Node { return il.Toks }
func (il *IdentifierList) SetTokens(toks []Node) { il.Toks = toks }
func (il *IdentifierList) Pos() token.Pos { return findFrom(il) }
func (il *IdentifierList) End() token.Pos { return findTo(il) }
func (il *IdentifierList) GetIdentifiers() []Node { return il.Identifiers }
func (il *IdentifierList) GetIndex(pos token.Pos) int {
if !isEnclose(il, pos) {
return -1
}
var idx int
for _, comma := range il.Commas {
if 0 > token.ComparePos(comma.Pos(), pos) {
idx += 1
idx++
}
}
return idx
Expand Down Expand Up @@ -546,20 +546,19 @@ func (t *SQLToken) Render(opts *RenderOptions) string {
}

func renderSQLWord(v *token.SQLWord, opts *RenderOptions) string {
isIdentifer := v.Kind == dialect.Unmatched
if isIdentifer {
if opts.IdentiferQuated {
isIdentifier := v.Kind == dialect.Unmatched
if isIdentifier {
if opts.IdentifierQuated {
v.QuoteStyle = '`'
return v.String()
}
return v.String()
} else {
// is keyword
if opts.LowerCase {
return strings.ToLower(v.String())
}
return strings.ToUpper(v.String())
}
// is keyword
if opts.LowerCase {
return strings.ToLower(v.String())
}
return strings.ToUpper(v.String())
}

func findFrom(node Node) token.Pos {
Expand Down
22 changes: 11 additions & 11 deletions internal/completer/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (c *Completer) Complete(text string, params lsp.CompletionParams, lowercase
if err != nil {
return nil, err
}
definedSubQuerys, err := parseutil.ExtractSubQueryViews(parsed, pos)
definedSubQueries, err := parseutil.ExtractSubQueryViews(parsed, pos)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -154,14 +154,14 @@ func (c *Completer) Complete(text string, params lsp.CompletionParams, lowercase
items = append(items, candidates...)
}
if completionTypeIs(ctx.types, CompletionTypeSubQuery) {
candidates := c.SubQueryCandidates(definedSubQuerys)
candidates := c.SubQueryCandidates(definedSubQueries)
if withBackQuote {
candidates = toQuotedCandidates(candidates)
}
items = append(items, candidates...)
}
if completionTypeIs(ctx.types, CompletionTypeSubQueryColumn) {
candidates := c.SubQueryColumnCandidates(definedSubQuerys)
candidates := c.SubQueryColumnCandidates(definedSubQueries)
if withBackQuote {
candidates = toQuotedCandidates(candidates)
}
Expand Down Expand Up @@ -272,7 +272,7 @@ type CompletionContext struct {

func getCompletionTypes(nw *parseutil.NodeWalker) *CompletionContext {
memberIdentifierMatcher := astutil.NodeMatcher{
NodeTypes: []ast.NodeType{ast.TypeMemberIdentifer},
NodeTypes: []ast.NodeType{ast.TypeMemberIdentifier},
}

syntaxPos := parseutil.CheckSyntaxPosition(nw)
Expand All @@ -282,7 +282,7 @@ func getCompletionTypes(nw *parseutil.NodeWalker) *CompletionContext {
case syntaxPos == parseutil.ColName:
if nw.CurNodeIs(memberIdentifierMatcher) {
// has parent
mi := nw.CurNodeTopMatched(memberIdentifierMatcher).(*ast.MemberIdentifer)
mi := nw.CurNodeTopMatched(memberIdentifierMatcher).(*ast.MemberIdentifier)
t = []completionType{
CompletionTypeColumn,
CompletionTypeSubQueryColumn,
Expand All @@ -309,7 +309,7 @@ func getCompletionTypes(nw *parseutil.NodeWalker) *CompletionContext {
case syntaxPos == parseutil.SelectExpr || syntaxPos == parseutil.CaseValue:
if nw.CurNodeIs(memberIdentifierMatcher) {
// has parent
mi := nw.CurNodeTopMatched(memberIdentifierMatcher).(*ast.MemberIdentifer)
mi := nw.CurNodeTopMatched(memberIdentifierMatcher).(*ast.MemberIdentifier)
t = []completionType{
CompletionTypeColumn,
CompletionTypeView,
Expand All @@ -333,7 +333,7 @@ func getCompletionTypes(nw *parseutil.NodeWalker) *CompletionContext {
case syntaxPos == parseutil.TableReference:
if nw.CurNodeIs(memberIdentifierMatcher) {
// has parent
mi := nw.CurNodeTopMatched(memberIdentifierMatcher).(*ast.MemberIdentifer)
mi := nw.CurNodeTopMatched(memberIdentifierMatcher).(*ast.MemberIdentifier)
t = []completionType{
CompletionTypeTable,
CompletionTypeView,
Expand All @@ -355,7 +355,7 @@ func getCompletionTypes(nw *parseutil.NodeWalker) *CompletionContext {
case syntaxPos == parseutil.WhereCondition:
if nw.CurNodeIs(memberIdentifierMatcher) {
// has parent
mi := nw.CurNodeTopMatched(memberIdentifierMatcher).(*ast.MemberIdentifer)
mi := nw.CurNodeTopMatched(memberIdentifierMatcher).(*ast.MemberIdentifier)
t = []completionType{
CompletionTypeColumn,
CompletionTypeView,
Expand Down Expand Up @@ -410,13 +410,13 @@ func getCompletionTypes(nw *parseutil.NodeWalker) *CompletionContext {
}

func filterCandidates(candidates []lsp.CompletionItem, lastWord string) []lsp.CompletionItem {
filterd := []lsp.CompletionItem{}
filtered := []lsp.CompletionItem{}
for _, candidate := range candidates {
if strings.HasPrefix(strings.ToUpper(candidate.Label), strings.ToUpper(lastWord)) {
filterd = append(filterd, candidate)
filtered = append(filtered, candidate)
}
}
return filterd
return filtered
}

func getLine(text string, line int) string {
Expand Down
8 changes: 4 additions & 4 deletions internal/database/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ type SSHConfig struct {
PrivateKey string `json:"privateKey" yaml:"privateKey"`
}

func (c *SSHConfig) Validate() error {
if c.Host == "" {
func (s *SSHConfig) Validate() error {
if s.Host == "" {
return errors.New("required: connections[]sshConfig.host")
}
if c.User == "" {
if s.User == "" {
return errors.New("required: connections[].sshConfig.user")
}
if c.PrivateKey == "" {
if s.PrivateKey == "" {
return errors.New("required: connections[].sshConfig.privateKey")
}
return nil
Expand Down
Loading

0 comments on commit 088ad8a

Please sign in to comment.