Skip to content

fix: fall back to file extension for usages language with custom match patterns - #598

Merged
JamieSinn merged 3 commits into
mainfrom
fix/custom-pattern-language
Oct 14, 2026
Merged

JamieSinn merged 3 commits into
mainfrom
fix/custom-pattern-language

Conversation

@jonathannorris

@jonathannorris jonathannorris commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Summary

  • dvc usages sets each reference's language from LANGUAGE_MAP, which only covers the built-in parser extensions. Files matched with a custom --match-pattern for any other extension (e.g. html) got language: undefined, which JSON.stringify drops, so the code usages upload fails since the API requires language.
  • Fall back to the file extension when it isn't in LANGUAGE_MAP.
  • Only use the extension as the language when it matches [a-z0-9]{1,16}; otherwise fall back to unknown.
  • Add an HTML fixture and a test covering a custom html match pattern with --format json.

@jonathannorris
jonathannorris marked this pull request as ready for review October 13, 2026 17:41
@jonathannorris
jonathannorris requested a review from a team as a code owner October 13, 2026 17:41
@jonathannorris
jonathannorris requested review from suthar26 and a balanced review from Copilot and removed request for Copilot October 13, 2026 17:41
Copilot AI balanced review requested due to automatic review settings October 13, 2026 18:09

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.

🟡 Changes recommended

Prototype-inherited map entries can violate the helper’s string return contract, and the integration test uses unsafe shared state.

2 open findings
What changed in this PR

Adds safe language fallback handling for custom usage match patterns.

Changes:

  • Maps unknown safe extensions to lowercase language names.
  • Defaults unsafe extensions to unknown.
  • Adds HTML fixture and unit/integration coverage.
File Description
test-utils/​fixtures/​usages/​sample.html Adds HTML usage fixture.
src/​utils/​parsers/​language.test.ts Tests language mapping and fallbacks.
src/​utils/​parsers/​index.ts Adds extension-to-language fallback.
src/​utils/​parsers/​BaseParser.ts Applies fallback to usage references.
src/​commands/​usages/​usages.test.ts Tests custom HTML pattern output.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/commands/usages/usages.test.ts Outdated
Comment thread src/utils/parsers/index.ts Outdated
@JamieSinn
JamieSinn merged commit 5504e96 into main Oct 14, 2026
6 checks passed
@JamieSinn
JamieSinn deleted the fix/custom-pattern-language branch October 14, 2026 17:05
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.

3 participants