提交 a12c05cb 编写于 作者: A amieres 提交者: Phillip Carter

Removed NoSourceCode at GetDeclarationLocation (#4277)

* GetDeclarationLocation no check for file to exist

Removed check for NoSourceCode error from TypeCheckInfo.GetDeclarationLocation.
It was checking for a file to exist and failing if it did not.

fsharp/FSharp.Compiler.Service#821

* Update EditorTests.fs

* GetDeclarationLocation: check TypeProvider items

* GetDeclarationLocation: added filename

* GetDeclarationLocation: fixed TypeProvider fail

* GetDeclarationLocation: TypeProvider with Location attr

* Added check for file existence

* Update GotoDefinition.fs

* Added check for file existence

* Added check for file existence

* Update Tests.LanguageService.GotoDefinition.fs

* Update service.fs
上级 32307bcc
......@@ -1214,32 +1214,28 @@ type TypeCheckInfo
Some (FSharpFindDeclResult.ExternalDecl (assref.Name, ExternalSymbol.Type fullName))
| _ -> None
| _ -> None
match result with
| Some x -> x
| None ->
let fail defaultReason =
match item.Item with
#if !NO_EXTENSIONTYPING
| SymbolHelpers.ItemIsProvidedType g (tcref) -> FSharpFindDeclResult.DeclNotFound (FSharpFindDeclFailureReason.ProvidedType(tcref.DisplayName))
| Item.CtorGroup(name, ProvidedMeth(_)::_)
| Item.MethodGroup(name, ProvidedMeth(_)::_, _)
| Item.Property(name, ProvidedProp(_)::_) -> FSharpFindDeclResult.DeclNotFound (FSharpFindDeclFailureReason.ProvidedMember(name))
| Item.Event(ProvidedEvent(_) as e) -> FSharpFindDeclResult.DeclNotFound (FSharpFindDeclFailureReason.ProvidedMember(e.EventName))
| Item.ILField(ProvidedField(_) as f) -> FSharpFindDeclResult.DeclNotFound (FSharpFindDeclFailureReason.ProvidedMember(f.FieldName))
#endif
| _ -> FSharpFindDeclResult.DeclNotFound defaultReason
match rangeOfItem g preferFlag item.Item with
| None -> fail (FSharpFindDeclFailureReason.Unknown "")
| Some itemRange ->
let projectDir = Filename.directoryName (if projectFileName = "" then mainInputFileName else projectFileName)
let filename = fileNameOfItem g (Some projectDir) itemRange item.Item
if FileSystem.SafeExists filename then
FSharpFindDeclResult.DeclFound (mkRange filename itemRange.Start itemRange.End)
else
fail FSharpFindDeclFailureReason.NoSourceCode // provided items may have TypeProviderDefinitionLocationAttribute that binds them to some location
let range = fileNameOfItem g (Some projectDir) itemRange item.Item
mkRange range itemRange.Start itemRange.End
|> FSharpFindDeclResult.DeclFound
| None ->
match item.Item with
#if !NO_EXTENSIONTYPING
// provided items may have TypeProviderDefinitionLocationAttribute that binds them to some location
| Item.CtorGroup (name, ProvidedMeth (_)::_ )
| Item.MethodGroup(name, ProvidedMeth (_)::_, _)
| Item.Property (name, ProvidedProp (_)::_ ) -> FSharpFindDeclFailureReason.ProvidedMember name
| Item.Event ( ProvidedEvent(_) as e ) -> FSharpFindDeclFailureReason.ProvidedMember e.EventName
| Item.ILField ( ProvidedField(_) as f ) -> FSharpFindDeclFailureReason.ProvidedMember f.FieldName
| SymbolHelpers.ItemIsProvidedType g (tcref) -> FSharpFindDeclFailureReason.ProvidedType tcref.DisplayName
#endif
| _ -> FSharpFindDeclFailureReason.Unknown ""
|> FSharpFindDeclResult.DeclNotFound
)
(fun msg ->
Trace.TraceInformation(sprintf "FCS: recovering from error in GetDeclarationLocation: '%s'" msg)
......
......@@ -768,6 +768,17 @@ let _ = Threading.Buzz = null
("Threading", (6, 8, 6, 17))
("Test", (1, 0, 1, 0))|]
[<Test>]
let ``GetDeclarationLocation should not require physical file`` () =
let input = "let abc = 1\nlet xyz = abc"
let file = "/home/user/Test.fsx"
let _, typeCheckResults = parseAndCheckScript(file, input)
let location = typeCheckResults.GetDeclarationLocation(2, 13, "let xyz = abc", ["abc"]) |> Async.RunSynchronously
match location with
| FSharpFindDeclResult.DeclFound r -> Some (r.StartLine, r.StartColumn, r.EndLine, r.EndColumn, "<=== Found here." )
| _ -> Some (0 , 0 , 0 , 0 , "Not Found. Should not require physical file." )
|> shouldEqual (Some (1 , 4 , 1 , 7 , "<=== Found here." ))
//-------------------------------------------------------------------------------
......
......@@ -74,9 +74,6 @@ module internal GotoDefinition =
|> GotoDefinitionResult_DEPRECATED.MakeError
else
match typedResults.GetDeclarationLocation (line+1, colIdent, lineStr, qualId, false) |> Async.RunSynchronously with
| FSharpFindDeclResult.DeclFound m ->
let span = TextSpan (iStartLine = m.StartLine-1, iEndLine = m.StartLine-1, iStartIndex = m.StartColumn, iEndIndex = m.StartColumn)
GotoDefinitionResult_DEPRECATED.MakeSuccess(m.FileName, span)
| FSharpFindDeclResult.DeclNotFound(reason) ->
if makeAnotherAttempt then gotoDefinition true
else
......@@ -88,6 +85,11 @@ module internal GotoDefinition =
| FSharpFindDeclFailureReason.ProvidedType(typeName) -> String.Format(Strings.GotoDefinitionFailed_ProvidedType(), typeName)
| FSharpFindDeclFailureReason.ProvidedMember(name) -> String.Format(Strings.GotoDefinitionFailed_ProvidedMember(), name)
GotoDefinitionResult_DEPRECATED.MakeError text
| FSharpFindDeclResult.DeclFound m when System.IO.File.Exists m.FileName ->
let span = TextSpan (iStartLine = m.StartLine-1, iEndLine = m.StartLine-1, iStartIndex = m.StartColumn, iEndIndex = m.StartColumn)
GotoDefinitionResult_DEPRECATED.MakeSuccess(m.FileName, span)
| FSharpFindDeclResult.DeclFound _ (* File does not exist *) ->
GotoDefinitionResult_DEPRECATED.MakeError(Strings.GotoDefinitionFailed_NotSourceCode())
| FSharpFindDeclResult.ExternalDecl _ ->
GotoDefinitionResult_DEPRECATED.MakeError(Strings.GotoDefinitionFailed_NotSourceCode())
else
......
......@@ -330,10 +330,7 @@ type UsingMSBuild() =
type T = N1.T<"", 1>
""",
marker = "T<",
f = (fun (_, result) ->
Assert.IsFalse(result.Success)
Assert.That(result.ErrorDescription, Does.Contain("provided type 'T'"))
),
f = (fun (_, result) -> Assert.IsFalse(result.Success) ),
addtlRefAssy = [PathRelativeToTestAssembly(@"UnitTests\MockTypeProviders\DummyProviderForLanguageServiceTesting.dll")]
)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册