44using System ;
55using System . Diagnostics ;
66using System . IO ;
7- using System . Linq ;
87using System . Threading ;
98using System . Threading . Tasks ;
10- using Microsoft . AspNetCore . Razor ;
119using Microsoft . AspNetCore . Razor . Language ;
1210using Microsoft . CodeAnalysis . Razor . DocumentMapping ;
1311using Microsoft . CodeAnalysis . Razor . Logging ;
@@ -131,11 +129,15 @@ private async Task<LspRange> GetNavigateRangeAsync(IDocumentSnapshot documentSna
131129 var literalText = token . ValueText ;
132130 _logger . LogDebug ( $ "Found string literal: { literalText } ") ;
133131
134- // Try to resolve the file path
135- if ( TryResolveFilePath ( documentSnapshot , literalText , out var resolvedPath ) )
132+ // Only process if it looks like a Razor file path
133+ if ( literalText . IsRazorFilePath ( ) )
136134 {
137- _logger . LogDebug ( $ "Resolved file path: { resolvedPath } ") ;
138- return [ LspFactory . CreateLocation ( resolvedPath , LspFactory . DefaultRange ) ] ;
135+ // Try to resolve the file path
136+ if ( TryResolveFilePath ( documentSnapshot , literalText , out var resolvedPath ) )
137+ {
138+ _logger . LogDebug ( $ "Resolved file path: { resolvedPath } ") ;
139+ return [ LspFactory . CreateLocation ( resolvedPath , LspFactory . DefaultRange ) ] ;
140+ }
139141 }
140142 }
141143
@@ -151,18 +153,10 @@ private bool TryResolveFilePath(IDocumentSnapshot documentSnapshot, string fileP
151153 return false ;
152154 }
153155
154- // Check if the file extension is .cshtml or .razor
155- var extension = Path . GetExtension ( filePath ) ;
156- if ( ! extension . Equals ( ".cshtml" , StringComparison . OrdinalIgnoreCase ) &&
157- ! extension . Equals ( ".razor" , StringComparison . OrdinalIgnoreCase ) )
158- {
159- return false ;
160- }
161-
162156 var project = documentSnapshot . Project ;
163157
164158 // Handle tilde paths (~/ or ~\) - these are relative to the project root
165- if ( filePath . StartsWith ( "~/" ) || filePath . StartsWith ( "~ \\ " ) )
159+ if ( filePath is [ '~' , '/' or ' \\ ' , .. ] )
166160 {
167161 var projectDirectory = Path . GetDirectoryName ( project . FilePath ) ;
168162 if ( projectDirectory is null )
@@ -174,14 +168,6 @@ private bool TryResolveFilePath(IDocumentSnapshot documentSnapshot, string fileP
174168 var relativePath = filePath . Substring ( 2 ) . Replace ( '/' , Path . DirectorySeparatorChar ) . Replace ( '\\ ' , Path . DirectorySeparatorChar ) ;
175169 var candidatePath = Path . GetFullPath ( Path . Combine ( projectDirectory , relativePath ) ) ;
176170
177- // Check using path comparison since the project might not have the document loaded yet
178- var matchingPath = project . DocumentFilePaths . FirstOrDefault ( d => PathUtilities . OSSpecificPathComparer . Equals ( d , candidatePath ) ) ;
179- if ( matchingPath is not null )
180- {
181- resolvedPath = matchingPath ;
182- return true ;
183- }
184-
185171 if ( project . ContainsDocument ( candidatePath ) )
186172 {
187173 resolvedPath = candidatePath ;
@@ -196,14 +182,6 @@ private bool TryResolveFilePath(IDocumentSnapshot documentSnapshot, string fileP
196182 var normalizedPath = filePath . Replace ( '/' , Path . DirectorySeparatorChar ) . Replace ( '\\ ' , Path . DirectorySeparatorChar ) ;
197183 var candidatePath = Path . GetFullPath ( Path . Combine ( currentDocumentDirectory , normalizedPath ) ) ;
198184
199- // Check using path comparison since the project might not have the document loaded yet
200- var matchingPath = project . DocumentFilePaths . FirstOrDefault ( d => PathUtilities . OSSpecificPathComparer . Equals ( d , candidatePath ) ) ;
201- if ( matchingPath is not null )
202- {
203- resolvedPath = matchingPath ;
204- return true ;
205- }
206-
207185 if ( project . ContainsDocument ( candidatePath ) )
208186 {
209187 resolvedPath = candidatePath ;
0 commit comments