Skip to content

Improve Makefile navigation for kernel-style conditionals and includes#21

Merged
owenrumney merged 2 commits into
mainfrom
fix/tidy-up-more-references
Jul 11, 2026
Merged

Improve Makefile navigation for kernel-style conditionals and includes#21
owenrumney merged 2 commits into
mainfrom
fix/tidy-up-more-references

Conversation

@owenrumney

Copy link
Copy Markdown
Owner

Fix go-to-definition for export/override/conditional variable names, add
support for else-if conditional chains, and resolve safe computed
include paths for linking into included Makefiles.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves Makefile navigation by enhancing parsing and resolution of kernel-style constructs so the language server can provide more accurate go-to-definition/references across directives, conditionals (including else-if), and computed include paths.

Changes:

  • Resolve computed include paths (e.g. $(srctree) / $(addprefix ...)) and carry resolved include locations into go-to-definition.
  • Parse else-if conditional chains and capture variable references in conditional headers and directives for navigation.
  • Bump VS Code extension version and adjust extension install to use --force.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
vscode-make-ls/package.json Bumps extension version for the new navigation features.
vscode-make-ls/package-lock.json Keeps lockfile version in sync with the extension version bump.
Makefile Forces VSIX reinstall during extension-install to ease iteration.
internal/resolver/resolver.go Expands and resolves computed include paths and merges included Makefile models.
internal/resolver/resolver_test.go Adds tests covering computed and addprefix include path resolution.
internal/resolver/eval.go Introduces a small evaluator to expand a subset of Make functions for include resolution.
internal/parser/parser.go Adds else-if parsing, directive/conditional var refs, and include-arg splitting that respects $() nesting.
internal/parser/parser_test.go Adds tests for else-if parsing, computed includes, and conditional var-ref ranges.
internal/model/model.go Extends Include with ResolvedPath and Conditional with VarRefs for navigation.
internal/handler/handler.go Improves definition/references for directives/conditionals and uses resolved include paths for navigation.
internal/handler/handler_test.go Adds integration-style tests for kernel-like snippets and computed include go-to-definition.
Files not reviewed (1)
  • vscode-make-ls/package-lock.json: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/parser/parser.go
Comment on lines 553 to 557
inc := &model.Include{
Path: strings.TrimSpace(m[2]),
Path: paths[0],
Range: lineRange(lineNum, 0, len(fullLine)),
Optional: optional,
}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in follow-up. Conditional include parsing now preserves the full include expression instead of truncating to the first token, and computed/multi-include resolution is covered by tests.

Comment on lines +73 to +80
expanded := ctx.expandText(inc.Path)
if expanded == "" {
expanded = inc.Path
}
fields := strings.Fields(expanded)
if len(fields) == 0 {
fields = []string{expanded}
}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in follow-up. resolveIncludePaths now returns no paths for whitespace-only expansions, so it no longer falls back to a bogus path under baseDir.

Comment thread internal/resolver/resolver.go
Comment thread internal/resolver/eval.go
Comment on lines +161 to +182
func extractDelimited(s string, start int) (int, string, bool) {
open := s[start]
closing := byte(')')
if open == '{' {
closing = '}'
}
depth := 1
for i := start + 1; i < len(s); i++ {
if s[i] == '$' && i+1 < len(s) && (s[i+1] == '(' || s[i+1] == '{') {
depth++
i++
continue
}
if s[i] == closing {
depth--
if depth == 0 {
return i, s[start+1 : i], true
}
}
}
return 0, "", false
}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in follow-up. extractDelimited now tracks nested closing delimiters with a stack, so mixed ${...} inside $(...) expands correctly. Added regression coverage for mixed nesting.

Fix go-to-definition for export/override/conditional variable names, add
support for else-if conditional chains, and resolve safe computed
include paths for linking into included Makefiles.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • vscode-make-ls/package-lock.json: Generated file

Comment on lines +378 to +393
func preferEarlierVariableDefinition(mf *model.Makefile, current *model.Variable) *model.Variable {
var best *model.Variable
for _, v := range mf.Variables {
if v.Name != current.Name {
continue
}
if v.NameRange.Start.Line > current.NameRange.Start.Line || (v.NameRange.Start.Line == current.NameRange.Start.Line && v.NameRange.Start.Character >= current.NameRange.Start.Character) {
continue
}
best = v
}
if best != nil {
return best
}
return current
}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in follow-up. The earlier-definition preference is now restricted to override assignments and only searches earlier entries in mf.Variables, so merged include vars do not get picked accidentally.

Comment on lines +646 to 652
path := inc.ResolvedPath
if path == "" {
path = inc.Path
}
return []lsp.Location{{
URI: lsp.DocumentURI("file://" + inc.Path),
URI: lsp.DocumentURI("file://" + path),
Range: lsp.Range{},

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in follow-up. Include-definition URIs are now constructed via net/url + filepath.ToSlash, so file URIs are valid and properly escaped.

Comment thread internal/resolver/eval.go Outdated
@owenrumney owenrumney merged commit e9e0da8 into main Jul 11, 2026
3 checks passed
@owenrumney owenrumney deleted the fix/tidy-up-more-references branch July 11, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants