Skip to content

Commit 1422322

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
Fix go to definition to symbols defined in referenced assemblies and have not normalized file paths (#3773)
* fix Solution.TryGetDocumentFromPath for relative paths * temp logging * debug * normalize range.filename in TaskPickle * remove debug * Revert "normalize range.filename in TaskPickle" This reverts commit 31967a5. * normalize full paths in mkRange * remove null check
1 parent d2cb414 commit 1422322

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/fsharp/range.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ type range(code:int64) =
170170
override r.Equals(obj) = match obj with :? range as r2 -> code = r2.Code | _ -> false
171171
override r.GetHashCode() = hash code
172172

173-
let mkRange f b e = range (fileIndexOfFile f, b, e)
173+
let mkRange f b e =
174+
// remove relative parts from full path
175+
let normalizedFilePath = if Path.IsPathRooted f then try Path.GetFullPath f with _ -> f else f
176+
range (fileIndexOfFile normalizedFilePath, b, e)
177+
174178
let mkFileIndexRange fi b e = range (fi, b, e)
175179

176180
(* end representation, start derived ops *)

vsintegration/src/FSharp.Editor/Common/CodeAnalysisExtensions.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module internal Microsoft.VisualStudio.FSharp.Editor.CodeAnalysisExtensions
33

44
open Microsoft.CodeAnalysis
55
open Microsoft.FSharp.Compiler.Range
6+
open System.IO
67

78
type Project with
89

@@ -41,7 +42,9 @@ type Solution with
4142

4243
/// Try to find the documentId corresponding to the provided filepath within this solution
4344
member self.TryGetDocumentFromPath filePath =
44-
self.GetDocumentIdsWithFilePath filePath
45+
// It's crucial to normalize file path here (specificaly, remove relative parts),
46+
// otherwise Roslyn does not find documents.
47+
self.GetDocumentIdsWithFilePath (Path.GetFullPath filePath)
4548
|> Seq.tryHead |> Option.map (fun docId -> self.GetDocument docId)
4649

4750

0 commit comments

Comments
 (0)