diff --git a/src/fsharp/range.fs b/src/fsharp/range.fs index f627e00157c724952c06f5227e933de190b10e18..aed660be56ce811452a545b62aecf0b6001984cb 100755 --- a/src/fsharp/range.fs +++ b/src/fsharp/range.fs @@ -170,7 +170,11 @@ type range(code:int64) = override r.Equals(obj) = match obj with :? range as r2 -> code = r2.Code | _ -> false override r.GetHashCode() = hash code -let mkRange f b e = range (fileIndexOfFile f, b, e) +let mkRange f b e = + // remove relative parts from full path + let normalizedFilePath = if Path.IsPathRooted f then try Path.GetFullPath f with _ -> f else f + range (fileIndexOfFile normalizedFilePath, b, e) + let mkFileIndexRange fi b e = range (fi, b, e) (* end representation, start derived ops *) diff --git a/vsintegration/src/FSharp.Editor/Common/CodeAnalysisExtensions.fs b/vsintegration/src/FSharp.Editor/Common/CodeAnalysisExtensions.fs index 4198f17151f8fa9620b36e3f8de36725b87bacd8..f75bb4020c99f6a0411339c9a1a5789775127714 100644 --- a/vsintegration/src/FSharp.Editor/Common/CodeAnalysisExtensions.fs +++ b/vsintegration/src/FSharp.Editor/Common/CodeAnalysisExtensions.fs @@ -3,6 +3,7 @@ module internal Microsoft.VisualStudio.FSharp.Editor.CodeAnalysisExtensions open Microsoft.CodeAnalysis open Microsoft.FSharp.Compiler.Range +open System.IO type Project with @@ -41,7 +42,9 @@ type Solution with /// Try to find the documentId corresponding to the provided filepath within this solution member self.TryGetDocumentFromPath filePath = - self.GetDocumentIdsWithFilePath filePath + // It's crucial to normalize file path here (specificaly, remove relative parts), + // otherwise Roslyn does not find documents. + self.GetDocumentIdsWithFilePath (Path.GetFullPath filePath) |> Seq.tryHead |> Option.map (fun docId -> self.GetDocument docId)