Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't serialize error location using roast but encoding/json #1020

Merged
merged 1 commit into from
Aug 28, 2024
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
19 changes: 14 additions & 5 deletions bundle/regal/ast/imports.rego
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,28 @@ imported_identifiers contains _imported_identifier(imp) if {
some imp in imports

imp.path.value[0].value in {"input", "data"}
count(imp.path.value) > 1
}

# METADATA
# description: |
# map of all imported paths in the input module, keyed by their identifier or "namespace"
resolved_imports[identifier] := path if {
some _import in imports
some identifier in imported_identifiers

_import.path.value[0].value == "data"
count(_import.path.value) > 1
# this should really be just a 1:1 mapping, but until OPA 1.0 we cannot
# trust that there are no duplicate imports, or imports shadowing other
# imports, which may render a runtime error here if two paths are written
# to the same identifier key ... simplify this post 1.0
paths := [path |
some imp in imports

identifier := _imported_identifier(_import)
path := [part.value | some part in _import.path.value]
_imported_identifier(imp) == identifier

path := [part.value | some part in imp.path.value]
]

path := paths[0]
}

# METADATA
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/bundles/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c *Cache) Refresh() ([]string, error) {
var foundBundleRoots []string

err := filepath.Walk(c.workspacePath, func(path string, info os.FileInfo, _ error) error {
if info.IsDir() && (info.Name() == ".git" || info.Name() == ".idea") {
if info.IsDir() && (info.Name() == ".git" || info.Name() == ".idea" || info.Name() == "node_modules") {
return filepath.SkipDir
}

Expand Down
5 changes: 1 addition & 4 deletions internal/lsp/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package lsp

import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"

"github.com/anderseknert/roast/pkg/encoding"

"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/storage"

Expand Down Expand Up @@ -84,8 +83,6 @@ func updateParse(ctx context.Context, cache *cache.Cache, store storage.Store, f
Location: parseError.Location,
})
} else {
json := encoding.JSON()

jsonErrors, err := json.Marshal(unwrappedError)
if err != nil {
return false, fmt.Errorf("failed to marshal parse errors: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,7 @@ func (l *LanguageServer) loadWorkspaceContents(ctx context.Context, newOnly bool

// These directories often have thousands of items we don't care about,
// so don't even traverse them.
if d.IsDir() && (d.Name() == ".git" || d.Name() == ".idea") {
if d.IsDir() && (d.Name() == ".git" || d.Name() == ".idea" || d.Name() == "node_modules") {
return filepath.SkipDir
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/config/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func FilterIgnoredPaths(paths, ignore []string, checkFileExists bool, rootDir st
filtered := make([]string, 0, len(paths))

if err := walkPaths(paths, func(path string, info os.DirEntry, err error) error {
if info.IsDir() && (info.Name() == ".git" || info.Name() == ".idea") {
if info.IsDir() && (info.Name() == ".git" || info.Name() == ".idea" || info.Name() == "node_modules") {
return filepath.SkipDir
}
if !info.IsDir() && strings.HasSuffix(path, bundle.RegoExt) {
Expand Down