Skip to content

Commit

Permalink
Use betteralign for struct alignment
Browse files Browse the repository at this point in the history
Saving us some bytes ;) A few things had to be fixed, but nothing
I'd consider breaking.

Signed-off-by: Anders Eknert <anders@styra.com>
  • Loading branch information
anderseknert committed Sep 24, 2024
1 parent f6f2f6d commit af988c1
Show file tree
Hide file tree
Showing 29 changed files with 203 additions and 198 deletions.
14 changes: 7 additions & 7 deletions cmd/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ import (
// control the behavior of lint rules used.
type fixCommandParams struct {
configFile string
debug bool
format string
outputFile string
conflictMode string
disable repeatedStringFlag
disableAll bool
disableCategory repeatedStringFlag
enable repeatedStringFlag
enableAll bool
enableCategory repeatedStringFlag
format string
ignoreFiles repeatedStringFlag
noColor bool
outputFile string
rules repeatedStringFlag
timeout time.Duration
debug bool
disableAll bool
enableAll bool
noColor bool
dryRun bool
verbose bool
force bool
conflictMode string
}

func (p *fixCommandParams) getConfigFile() string {
Expand Down
12 changes: 6 additions & 6 deletions cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ import (
)

type lintCommandParams struct {
timeout time.Duration
configFile string
format string
outputFile string
failLevel string
rules repeatedStringFlag
disable repeatedStringFlag
disableCategory repeatedStringFlag
enable repeatedStringFlag
enableCategory repeatedStringFlag
ignoreFiles repeatedStringFlag
timeout time.Duration
noColor bool
debug bool
enablePrint bool
metrics bool
profile bool
disable repeatedStringFlag
disableAll bool
disableCategory repeatedStringFlag
enable repeatedStringFlag
enableAll bool
enableCategory repeatedStringFlag
ignoreFiles repeatedStringFlag
}

func (p *lintCommandParams) getConfigFile() string {
Expand Down
10 changes: 5 additions & 5 deletions cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ const (
)

type testCommandParams struct {
verbose bool
outputFormat *util.EnumFlag
coverage bool
runRegex string
ignore []string
threshold float64
timeout time.Duration
ignore []string
count int
verbose bool
coverage bool
bundleMode bool
benchmark bool
benchMem bool
runRegex string
count int
skipExitZero bool
varValues bool
}
Expand Down
8 changes: 4 additions & 4 deletions internal/lsp/bundles/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
// Cache is a struct that maintains a number of bundles in memory and
// provides a way to refresh them when the source files change.
type Cache struct {
workspacePath string
bundles map[string]*cacheBundle
errorLog io.Writer
bundles map[string]*cacheBundle
workspacePath string
}

type CacheOptions struct {
WorkspacePath string
ErrorLog io.Writer
WorkspacePath string
}

func NewCache(opts *CacheOptions) *Cache {
Expand Down Expand Up @@ -135,8 +135,8 @@ func (c *Cache) All() map[string]bundle.Bundle {
// hash of each source file in the bundle. Hashes are used to determine if
// the bundle should be reloaded.
type cacheBundle struct {
bundle bundle.Bundle
sourceDigests map[string][]byte
bundle bundle.Bundle
}

// Refresh loads the bundle from disk and updates the cache if any of the
Expand Down
36 changes: 22 additions & 14 deletions internal/lsp/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,53 @@ import (
// diagnostics for each file (including diagnostics gathered from linting files alongside other files).
type Cache struct {
// fileContents is a map of file URI to raw file contents received from the client
fileContents map[string]string
fileContentsMu sync.Mutex
fileContents map[string]string

// ignoredFileContents is a similar map of file URI to raw file contents
// but it's not queried for project level operations like goto definition,
// linting etc.
// ignoredFileContents is also cleared on the delete operation.
ignoredFileContents map[string]string
ignoredFileContentsMu sync.Mutex
ignoredFileContents map[string]string

// modules is a map of file URI to parsed AST modules from the latest file contents value
modules map[string]*ast.Module
moduleMu sync.Mutex
modules map[string]*ast.Module

// diagnosticsFile is a map of file URI to diagnostics for that file
diagnosticsFile map[string][]types.Diagnostic
diagnosticsFileMu sync.Mutex
diagnosticsFile map[string][]types.Diagnostic

// diagnosticsAggregate is a map of file URI to aggregate diagnostics for that file
diagnosticsAggregate map[string][]types.Diagnostic
diagnosticsAggregateMu sync.Mutex
diagnosticsAggregate map[string][]types.Diagnostic

// diagnosticsParseErrors is a map of file URI to parse errors for that file
diagnosticsParseErrors map[string][]types.Diagnostic
diagnosticsParseMu sync.Mutex

// builtinPositionsFile is a map of file URI to builtin positions for that file
builtinPositionsFile map[string]map[uint][]types.BuiltinPosition
builtinPositionsMu sync.Mutex

// keywordLocationsFile is a map of file URI to Rego keyword locations for that file
// to be used for hover hints.
keywordLocationsFile map[string]map[uint][]types.KeywordLocation
keywordLocationsMu sync.Mutex

// fileRefs is a map of file URI to refs that are defined in that file. These are
// intended to be used for completions in other files.
// fileRefs is expected to be updated when a file is successfully parsed.
fileRefs map[string]map[string]types.Ref
fileRefs map[string]map[string]types.Ref
fileContentsMu sync.Mutex

ignoredFileContentsMu sync.Mutex

moduleMu sync.Mutex

diagnosticsFileMu sync.Mutex

diagnosticsAggregateMu sync.Mutex

diagnosticsParseMu sync.Mutex

builtinPositionsMu sync.Mutex

keywordLocationsMu sync.Mutex

fileRefMu sync.Mutex
}

Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/commands/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type ParseOptions struct {
}

type ParseResult struct {
Target string
Location *ast.Location
Target string
}

// Parse is responsible for extracting the target and location from the given params command params sent from the client
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/completions/providers/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import (
)

type Options struct {
ClientIdentifier clients.Identifier
RootURI string
ClientIdentifier clients.Identifier
}
12 changes: 6 additions & 6 deletions internal/lsp/config/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
)

type Watcher struct {
Reload chan string
Drop chan struct{}
errorWriter io.Writer
Reload chan string
Drop chan struct{}

path string
pathUpdates chan string

fsWatcher *fsnotify.Watcher
fsWatcherLock sync.Mutex
fsWatcher *fsnotify.Watcher

errorWriter io.Writer
path string
fsWatcherLock sync.Mutex
}

type WatcherOpts struct {
Expand Down
6 changes: 3 additions & 3 deletions internal/lsp/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ type ConnectionOptions struct {
type ConnectionLoggingConfig struct {
Writer io.Writer

LogInbound bool
LogOutbound bool

// IncludeMethods is a list of methods to include in the request log.
// If empty, all methods are included. IncludeMethods takes precedence
// over ExcludeMethods.
IncludeMethods []string
// ExcludeMethods is a list of methods to exclude from the request log.
ExcludeMethods []string

LogInbound bool
LogOutbound bool
}

func (cfg *ConnectionLoggingConfig) ShouldLog(method string) bool {
Expand Down
6 changes: 3 additions & 3 deletions internal/lsp/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ const (
// https://www.codeproject.com/Articles/42279/%2FArticles%2F42279%2FInvestigating-Myers-diff-algorithm-Part-1-of-2

type operation struct {
Kind OpKind
Content []string // content from b
I1, I2 uint // indices of the line in a
J1 uint // indices of the line in b, J2 implied by len(Content)
Kind OpKind
I1, I2 uint // indices of the line in a
J1 uint // indices of the line in b, J2 implied by len(Content)
}

// operations returns the list of operations to convert a into b, consolidating
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func (l *LanguageServer) Eval(

type EvalPathResult struct {
Value any `json:"value"`
IsUndefined bool `json:"isUndefined"`
PrintOutput map[string]map[int][]string `json:"printOutput"`
IsUndefined bool `json:"isUndefined"`
}

func (l *LanguageServer) EvalWorkspacePath(
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ func updateAllDiagnostics(

// astError is copied from OPA but drop details as I (charlieegan3) had issues unmarshalling the field.
type astError struct {
Location *ast.Location `json:"location,omitempty"`
Code string `json:"code"`
Message string `json:"message"`
Location *ast.Location `json:"location,omitempty"`
}

func getRangeForViolation(item report.Violation) types.Range {
Expand Down
4 changes: 2 additions & 2 deletions internal/lsp/opa/oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ func New() *Oracle {

// DefinitionQuery defines a Rego definition query.
type DefinitionQuery struct {
Filename string // name of file to search for position inside of
Pos int // position to search for
Modules map[string]*ast.Module // workspace modules; buffer may shadow a file inside the workspace
Filename string // name of file to search for position inside of
Buffer []byte // buffer that overrides module with filename
Pos int // position to search for
}

var (
Expand Down
10 changes: 5 additions & 5 deletions internal/lsp/opa/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ const bom = 0xFEFF
// Scanner is used to tokenize an input stream of
// Rego source code.
type Scanner struct {
keywords map[string]tokens.Token
bs []byte
errors []Error
offset int
row int
col int
bs []byte
curr rune
width int
errors []Error
keywords map[string]tokens.Token
curr rune
regoV1Compatible bool
}

// Error represents a scanner error.
type Error struct {
Pos Position
Message string
Pos Position
}

// Position represents a point in the scanned source code.
Expand Down
8 changes: 4 additions & 4 deletions internal/lsp/rego/rego.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ var (
var preparedQueriesInitOnce sync.Once

type policy struct {
module *ast.Module
fileName string
contents string
module *ast.Module
}

func initialize() {
Expand Down Expand Up @@ -158,7 +158,7 @@ func AllKeywords(ctx context.Context, fileName, contents string, module *ast.Mod

var keywords map[string][]KeywordUse

value, err := queryToValue(ctx, keywordsPreparedQuery, policy{fileName, contents, module}, keywords)
value, err := queryToValue(ctx, keywordsPreparedQuery, policy{module, fileName, contents}, keywords)
if err != nil {
return nil, fmt.Errorf("failed querying code lenses: %w", err)
}
Expand All @@ -172,7 +172,7 @@ func AllRuleHeadLocations(ctx context.Context, fileName, contents string, module

var ruleHeads RuleHeads

value, err := queryToValue(ctx, ruleHeadLocationsPreparedQuery, policy{fileName, contents, module}, ruleHeads)
value, err := queryToValue(ctx, ruleHeadLocationsPreparedQuery, policy{module, fileName, contents}, ruleHeads)
if err != nil {
return nil, fmt.Errorf("failed querying code lenses: %w", err)
}
Expand All @@ -186,7 +186,7 @@ func CodeLenses(ctx context.Context, uri, contents string, module *ast.Module) (

var codeLenses []types.CodeLens

value, err := queryToValue(ctx, codeLensPreparedQuery, policy{uri, contents, module}, codeLenses)
value, err := queryToValue(ctx, codeLensPreparedQuery, policy{module, uri, contents}, codeLenses)
if err != nil {
return nil, fmt.Errorf("failed querying code lenses: %w", err)
}
Expand Down
17 changes: 9 additions & 8 deletions internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,17 @@ func NewLanguageServer(opts *LanguageServerOptions) *LanguageServer {
}

type LanguageServer struct {
conn *jsonrpc2.Conn

errorLog io.Writer

configWatcher *lsconfig.Watcher
loadedConfig *config.Config
loadedConfigLock sync.Mutex
regoStore storage.Store
conn *jsonrpc2.Conn

workspaceRootURI string
clientIdentifier clients.Identifier
configWatcher *lsconfig.Watcher
loadedConfig *config.Config

clientInitializationOptions types.InitializationOptions

cache *cache.Cache
regoStore storage.Store
bundleCache *bundles.Cache

completionsManager *completions.Manager
Expand All @@ -115,6 +111,11 @@ type LanguageServer struct {
templateFile chan fileUpdateEvent

webServer *web.Server

workspaceRootURI string
clientIdentifier clients.Identifier

loadedConfigLock sync.Mutex
}

// fileUpdateEvent is sent to a channel when an update is required for a file.
Expand Down
Loading

0 comments on commit af988c1

Please sign in to comment.