From 142232292ee2d4c6694c9f23ad97fbc001e2ee5c Mon Sep 17 00:00:00 2001 From: Vasily Kirichenko Date: Sun, 29 Oct 2017 08:57:40 +0300 Subject: [PATCH] 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 31967a5833b566ad3cfb6270d685c0eb012d38f5. * normalize full paths in mkRange * remove null check --- src/fsharp/range.fs | 6 +++++- .../src/FSharp.Editor/Common/CodeAnalysisExtensions.fs | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/fsharp/range.fs b/src/fsharp/range.fs index f627e0015..aed660be5 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 4198f1715..f75bb4020 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) -- GitLab