Skip to content

Commit

Permalink
Merge branch 'main' into i4k-fix-macos-go-cache-miss
Browse files Browse the repository at this point in the history
  • Loading branch information
i4ki committed Feb 12, 2024
2 parents f33ce22 + fd4bd4c commit e18418a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Given a version number `MAJOR.MINOR.PATCH`, we increment the:
- Add `terramate.config.generate.hcl_magic_header_comment_style` option for setting the generated comment style.
- Add support for formatting specific files and stdin (`terramate fmt [file...]` or `terramate fmt -`).

### Fixed

- Fix language server panic when root directory contain errors.

## 0.4.5

### Added
Expand Down
8 changes: 6 additions & 2 deletions ls/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,16 @@ func listFiles(fromFile string) ([]string, error) {
// is handled separately because it can be unsaved.
func (s *Server) checkFiles(files []string, currentFile string, currentContent string) error {
dir := filepath.Dir(currentFile)
root, rootdir, found, _ := config.TryLoadConfig(dir)
var experiments []string
root, rootdir, found, err := config.TryLoadConfig(dir)
if err == nil {
experiments = root.Tree().Node.Experiments()
}
if !found {
rootdir = s.workspace
}

parser, err := hcl.NewTerramateParser(rootdir, dir, root.Tree().Node.Experiments()...)
parser, err := hcl.NewTerramateParser(rootdir, dir, experiments...)
if err != nil {
return errors.E(err, "failed to create terramate parser")
}
Expand Down
29 changes: 29 additions & 0 deletions ls/ls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,35 @@ func TestDocumentOpen(t *testing.T) {
params.URI.Filename())
}

func TestDocumentRegressionErrorLoadingRootConfig(t *testing.T) {
t.Parallel()
f := lstest.Setup(t)

file := f.Sandbox.RootEntry().CreateFile("test.tm", "attr = 1")
f.Editor.CheckInitialize(f.Sandbox.RootDir())
f.Editor.Open("test.tm")

// root.config.tm diagnostic
r := <-f.Editor.Requests
assert.EqualStrings(t, "textDocument/publishDiagnostics", r.Method(),
"unexpected notification request")

var params lsp.PublishDiagnosticsParams
assert.NoError(t, json.Unmarshal(r.Params(), &params), "unmarshaling params")
assert.EqualInts(t, 0, len(params.Diagnostics))
assert.EqualStrings(t, filepath.Join(f.Sandbox.RootDir(), "root.config.tm"), params.URI.Filename())

// test.tm diagnostic
r = <-f.Editor.Requests
assert.EqualStrings(t, "textDocument/publishDiagnostics", r.Method(),
"unexpected notification request")

params = lsp.PublishDiagnosticsParams{}
assert.NoError(t, json.Unmarshal(r.Params(), &params), "unmarshaling params")
assert.EqualInts(t, 1, len(params.Diagnostics))
assert.EqualStrings(t, file.Path(), params.URI.Filename())
}

func TestDocumentChange(t *testing.T) {
t.Skip("not ready")

Expand Down

0 comments on commit e18418a

Please sign in to comment.