@@ -9,14 +9,29 @@ import type { MiseService } from "../miseService";
99import { expandPath } from "../utils/fileUtils" ;
1010import { getSvgIcon } from "../utils/iconUtils" ;
1111import { logger } from "../utils/logger" ;
12+ import { getCachedTomlParser } from "../utils/miseFileParser" ;
1213import { getCleanedToolName } from "../utils/miseUtilts" ;
13- import {
14- extractToolNamesFromLine ,
15- extractToolVersionFromLine ,
16- extractToolVersionFromSection ,
17- isPositionInToolsContext ,
18- parseToolsSectionHeader ,
19- } from "../utils/tomlParsing" ;
14+ import { buildToolIndex , type DeclaredTool } from "../utils/toolIndex" ;
15+
16+ function groupToolsByLine (
17+ document : vscode . TextDocument ,
18+ ) : Map < number , DeclaredTool [ ] > {
19+ const toolsByLine = new Map < number , DeclaredTool [ ] > ( ) ;
20+ const parser = getCachedTomlParser ( document ) ;
21+ if ( ! parser ) {
22+ return toolsByLine ;
23+ }
24+ for ( const tool of buildToolIndex ( parser ) ) {
25+ const line = tool . range . start . line ;
26+ const existing = toolsByLine . get ( line ) ;
27+ if ( existing ) {
28+ existing . push ( tool ) ;
29+ } else {
30+ toolsByLine . set ( line , [ tool ] ) ;
31+ }
32+ }
33+ return toolsByLine ;
34+ }
2035
2136const activeDecorationsPerFileAndTool : {
2237 [ filePath : string ] : {
@@ -69,34 +84,17 @@ export async function showToolVersionInline(
6984 // (e.g. `pkl` in [tools] AND `tools.pkl` in a task) would lose the first.
7085 const pendingDecorations = new Map < string , vscode . DecorationOptions [ ] > ( ) ;
7186
72- for ( let line = 0 ; line < document . lineCount ; line ++ ) {
87+ for ( const [ line , lineTools ] of groupToolsByLine ( document ) ) {
7388 try {
7489 const lineText = document . lineAt ( line ) . text ;
75- const trimmedLine = lineText . trim ( ) ;
76-
77- const { inContext, isInline, inToolOptionsSection } =
78- isPositionInToolsContext ( document , new vscode . Position ( line , 0 ) ) ;
79- // Option lines inside a `[tools.<name>]` section (version, os, ...)
80- // do not declare tools; the section header line does.
81- if ( ! inContext || inToolOptionsSection ) {
82- continue ;
83- }
84-
85- if ( trimmedLine . startsWith ( "#" ) || trimmedLine === "[tools]" ) {
86- continue ;
87- }
88-
89- const toolNamesRaw = extractToolNamesFromLine ( lineText ) ;
90- if ( toolNamesRaw . length === 0 ) {
91- continue ;
92- }
93-
94- const isToolsSectionHeader = ! ! parseToolsSectionHeader ( trimmedLine ) ;
90+ // task tools (`tools = { ... }`, `tools.<name> = ...`) get the
91+ // `name: version` annotation style; config tools show the version only
92+ const isInline = lineTools . some ( ( tool ) => tool . inTask ) ;
9593 const annotations : string [ ] = [ ] ;
9694 const usedTools : string [ ] = [ ] ;
9795
98- for ( const raw of toolNamesRaw ) {
99- const cleanedToolName = getCleanedToolName ( raw ) ;
96+ for ( const declaredTool of lineTools ) {
97+ const cleanedToolName = getCleanedToolName ( declaredTool . toolName ) ;
10098 if ( ! cleanedToolName ) {
10199 continue ;
102100 }
@@ -126,11 +124,7 @@ export async function showToolVersionInline(
126124 }
127125 }
128126
129- const reqVersion =
130- extractToolVersionFromLine ( lineText , raw ) ??
131- ( isToolsSectionHeader
132- ? extractToolVersionFromSection ( document , line )
133- : undefined ) ;
127+ const reqVersion = declaredTool . requestedVersion ;
134128 if ( reqVersion && resolvedVersion ) {
135129 // Strip a leading `v` from both sides so git-sourced tools
136130 // (e.g. `pipx:github/owner/repo` pinned to a tag like
@@ -258,32 +252,14 @@ export async function showOutdatedToolsGutterIcons(
258252 const updatedToolNames = new Set < string > ( ) ;
259253 const linesWithOutdatedTools : number [ ] = [ ] ;
260254
261- for ( let line = 0 ; line < document . lineCount ; line ++ ) {
255+ for ( const [ line , lineTools ] of groupToolsByLine ( document ) ) {
262256 try {
263- const lineText = document . lineAt ( line ) . text ;
264- const trimmedLine = lineText . trim ( ) ;
265-
266- const { inContext, inToolOptionsSection } = isPositionInToolsContext (
267- document ,
268- new vscode . Position ( line , 0 ) ,
269- ) ;
270- if ( ! inContext || inToolOptionsSection ) continue ;
271-
272- if ( trimmedLine . startsWith ( "#" ) || trimmedLine === "[tools]" ) {
273- continue ;
274- }
275-
276- const toolNamesRaw = extractToolNamesFromLine ( lineText ) ;
277- if ( toolNamesRaw . length === 0 ) {
278- continue ;
279- }
280-
281257 let hasOutdated = false ;
282258 const outdatedNames : string [ ] = [ ] ;
283259 const validToolNames : string [ ] = [ ] ;
284260
285- for ( const raw of toolNamesRaw ) {
286- const cleanedToolName = getCleanedToolName ( raw ) ;
261+ for ( const declaredTool of lineTools ) {
262+ const cleanedToolName = getCleanedToolName ( declaredTool . toolName ) ;
287263 if ( ! cleanedToolName ) {
288264 continue ;
289265 }
0 commit comments