Skip to content
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
1 change: 1 addition & 0 deletions docs/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ title: Changelog
* `[Added]` Add `lets self doc` command to open the online documentation in a browser.
* `[Added]` Show background update notifications for interactive sessions, with Homebrew-aware guidance and `LETS_CHECK_UPDATE` opt-out.
* `[Changed]` Centralize the `lets:` log prefix in the formatter and render debug messages in blue.
* `[Fixed]` Resolve `go to definition` from YAML merge aliases such as `<<: *test` to the referenced command in `lets self lsp`.

## [0.0.59](https://github.com/lets-cli/lets/releases/tag/v0.0.59)

Expand Down
1 change: 1 addition & 0 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func Main(version string, buildDate string) int {
if errors.As(err, &depErr) {
executor.PrintDependencyTree(depErr, os.Stderr)
log.Errorf("%s", depErr.FailureMessage())

return getExitCode(err, 1)
}

Expand Down
40 changes: 30 additions & 10 deletions internal/lsp/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,19 @@ func (h *definitionHandler) findMixinsDefinition(doc *string, params *lsp.Defini

filename := h.parser.extractFilenameFromMixins(doc, params.Position)
if filename == "" {
h.parser.log.Debugf("no mixin filename resolved at %s:%d:%d", path, params.Position.Line, params.Position.Character)
return nil, nil
}

absFilename := replacePathFilename(path, filename)

if !util.FileExists(absFilename) {
h.parser.log.Debugf("mixin target does not exist: %s", absFilename)
return nil, nil
}

h.parser.log.Debugf("resolved mixin definition %q -> %s", filename, absFilename)

return []lsp.Location{
{
URI: pathToURI(absFilename),
Expand All @@ -86,21 +90,28 @@ func (h *definitionHandler) findMixinsDefinition(doc *string, params *lsp.Defini
}

func (h *definitionHandler) findCommandDefinition(doc *string, params *lsp.DefinitionParams) (any, error) {
line := getLine(doc, params.Position.Line)
if line == "" {
return nil, nil
}
path := normalizePath(params.TextDocument.URI)

word := wordUnderCursor(line, &params.Position)
if word == "" {
commandName := h.parser.extractCommandReference(doc, params.Position)
if commandName == "" {
h.parser.log.Debugf("no command reference resolved at %s:%d:%d", path, params.Position.Line, params.Position.Character)
return nil, nil
}

command := h.parser.findCommand(doc, word)
command := h.parser.findCommand(doc, commandName)
if command == nil {
h.parser.log.Debugf("command reference %q did not match any local command", commandName)
return nil, nil
}

h.parser.log.Debugf(
"resolved command definition %q -> %s:%d:%d",
commandName,
path,
command.position.Line,
command.position.Character,
)

// TODO: theoretically we can have multiple commands with the same name if we have mixins
return []lsp.Location{
{
Expand Down Expand Up @@ -159,13 +170,22 @@ func (s *lspServer) textDocumentDefinition(context *glsp.Context, params *lsp.De
doc := s.storage.GetDocument(params.TextDocument.URI)

p := newParser(s.log)

switch p.getPositionType(doc, params.Position) {
positionType := p.getPositionType(doc, params.Position)
s.log.Debugf(
"definition request uri=%s line=%d char=%d type=%s",
normalizePath(params.TextDocument.URI),
params.Position.Line,
params.Position.Character,
positionType,
)

switch positionType {
case PositionTypeMixins:
return definitionHandler.findMixinsDefinition(doc, params)
case PositionTypeDepends:
case PositionTypeDepends, PositionTypeCommandAlias:
return definitionHandler.findCommandDefinition(doc, params)
default:
s.log.Debugf("definition request ignored: unsupported cursor position")
return nil, nil
}
}
Expand Down
17 changes: 16 additions & 1 deletion internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lsp
import (
"context"

"github.com/lets-cli/lets/internal/env"
"github.com/tliron/commonlog"
_ "github.com/tliron/commonlog/simple"
lsp "github.com/tliron/glsp/protocol_3_16"
Expand All @@ -24,8 +25,22 @@ func (s *lspServer) Run() error {
return s.server.RunStdio()
}

func lspLogVerbosity() int {
verbosity := 1

defer func() {
_ = recover()
}()

if env.DebugLevel() > 0 {
verbosity = 2
}

return verbosity
}

func Run(ctx context.Context, version string) error {
commonlog.Configure(1, nil)
commonlog.Configure(lspLogVerbosity(), nil)

logger := commonlog.GetLogger(lsName)
logger.Infof("Lets LSP server starting %s", version)
Expand Down
Loading
Loading