Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita12c05c

Browse files
amierescartermp
authored andcommitted
Removed NoSourceCode at GetDeclarationLocation (dotnet#4277)
* GetDeclarationLocation no check for file to existRemoved check for NoSourceCode error from TypeCheckInfo.GetDeclarationLocation.It was checking for a file to exist and failing if it did not.fsharp/fsharp-compiler-docs#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
1 parent32307bc commita12c05c

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

‎src/fsharp/service/service.fs‎

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,32 +1214,28 @@ type TypeCheckInfo
12141214
Some(FSharpFindDeclResult.ExternalDecl(assref.Name, ExternalSymbol.Type fullName))
12151215
|_-> None
12161216
|_-> None
1217-
12181217
match resultwith
12191218
| Some x-> x
1220-
| None->
1221-
letfail defaultReason=
1222-
match item.Itemwith
1219+
| None->
1220+
match rangeOfItem g preferFlag item.Itemwith
1221+
| Some itemRange->
1222+
letprojectDir= Filename.directoryName(if projectFileName=""then mainInputFileNameelse projectFileName)
1223+
letrange= fileNameOfItem g(Some projectDir) itemRange item.Item
1224+
mkRange range itemRange.Start itemRange.End
1225+
|> FSharpFindDeclResult.DeclFound
1226+
| None->
1227+
match item.Itemwith
12231228
#if!NO_EXTENSIONTYPING
1224-
| SymbolHelpers.ItemIsProvidedType g(tcref)-> FSharpFindDeclResult.DeclNotFound(FSharpFindDeclFailureReason.ProvidedType(tcref.DisplayName))
1225-
| Item.CtorGroup(name, ProvidedMeth(_)::_)
1226-
| Item.MethodGroup(name, ProvidedMeth(_)::_,_)
1227-
| Item.Property(name, ProvidedProp(_)::_)-> FSharpFindDeclResult.DeclNotFound(FSharpFindDeclFailureReason.ProvidedMember(name))
1228-
| Item.Event(ProvidedEvent(_)as e)-> FSharpFindDeclResult.DeclNotFound(FSharpFindDeclFailureReason.ProvidedMember(e.EventName))
1229-
| Item.ILField(ProvidedField(_)as f)-> FSharpFindDeclResult.DeclNotFound(FSharpFindDeclFailureReason.ProvidedMember(f.FieldName))
1229+
// provided items may have TypeProviderDefinitionLocationAttribute that binds them to some location
1230+
| Item.CtorGroup(name, ProvidedMeth(_)::_)
1231+
| Item.MethodGroup(name, ProvidedMeth(_)::_,_)
1232+
| Item.Property(name, ProvidedProp(_)::_)-> FSharpFindDeclFailureReason.ProvidedMember name
1233+
| Item.Event( ProvidedEvent(_)as e)-> FSharpFindDeclFailureReason.ProvidedMember e.EventName
1234+
| Item.ILField( ProvidedField(_)as f)-> FSharpFindDeclFailureReason.ProvidedMember f.FieldName
1235+
| SymbolHelpers.ItemIsProvidedType g(tcref)-> FSharpFindDeclFailureReason.ProvidedType tcref.DisplayName
12301236
#endif
1231-
|_-> FSharpFindDeclResult.DeclNotFound defaultReason
1232-
1233-
match rangeOfItem g preferFlag item.Itemwith
1234-
| None-> fail(FSharpFindDeclFailureReason.Unknown"")
1235-
| Some itemRange->
1236-
1237-
letprojectDir= Filename.directoryName(if projectFileName=""then mainInputFileNameelse projectFileName)
1238-
letfilename= fileNameOfItem g(Some projectDir) itemRange item.Item
1239-
if FileSystem.SafeExists filenamethen
1240-
FSharpFindDeclResult.DeclFound(mkRange filename itemRange.Start itemRange.End)
1241-
else
1242-
fail FSharpFindDeclFailureReason.NoSourceCode// provided items may have TypeProviderDefinitionLocationAttribute that binds them to some location
1237+
|_-> FSharpFindDeclFailureReason.Unknown""
1238+
|> FSharpFindDeclResult.DeclNotFound
12431239
)
12441240
(fun msg->
12451241
Trace.TraceInformation(sprintf"FCS: recovering from error in GetDeclarationLocation: '%s'" msg)

‎tests/service/EditorTests.fs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,17 @@ let _ = Threading.Buzz = null
768768
("Threading",(6,8,6,17))
769769
("Test",(1,0,1,0))|]
770770

771+
[<Test>]
772+
let``GetDeclarationLocation should not require physical file``()=
773+
letinput="let abc = 1\nlet xyz = abc"
774+
letfile="/home/user/Test.fsx"
775+
let_,typeCheckResults= parseAndCheckScript(file, input)
776+
letlocation= typeCheckResults.GetDeclarationLocation(2,13,"let xyz = abc",["abc"])|> Async.RunSynchronously
777+
match locationwith
778+
| FSharpFindDeclResult.DeclFound r-> Some(r.StartLine, r.StartColumn, r.EndLine, r.EndColumn,"<=== Found here.")
779+
|_-> Some(0,0,0,0,"Not Found. Should not require physical file.")
780+
|> shouldEqual(Some(1,4,1,7,"<=== Found here."))
781+
771782

772783
//-------------------------------------------------------------------------------
773784

‎vsintegration/src/FSharp.LanguageService/GotoDefinition.fs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module internal GotoDefinition =
4040
letls= textView.GetBuffer()|> Com.ThrowOnFailure1
4141
letlen= ls.GetLengthOfLine line|> Com.ThrowOnFailure1
4242
letlineStr= ls.GetLineText(line,0, line, len)|> Com.ThrowOnFailure1
43-
43+
4444
// in many cases we assume gotodef should work even if we don't stand on the identifier directly
4545
// treatTokenAsIdentifier governs if we want to have raw value of token (possibly operator) or if should always be considered as identifier
4646
let recgotoDefinition alwaysTreatTokenAsIdentifier=
@@ -74,9 +74,6 @@ module internal GotoDefinition =
7474
|> GotoDefinitionResult_DEPRECATED.MakeError
7575
else
7676
match typedResults.GetDeclarationLocation(line+1, colIdent, lineStr, qualId,false)|> Async.RunSynchronouslywith
77-
| FSharpFindDeclResult.DeclFound m->
78-
letspan= TextSpan(iStartLine= m.StartLine-1, iEndLine= m.StartLine-1, iStartIndex= m.StartColumn, iEndIndex= m.StartColumn)
79-
GotoDefinitionResult_DEPRECATED.MakeSuccess(m.FileName, span)
8077
| FSharpFindDeclResult.DeclNotFound(reason)->
8178
if makeAnotherAttemptthen gotoDefinitiontrue
8279
else
@@ -88,8 +85,13 @@ module internal GotoDefinition =
8885
| FSharpFindDeclFailureReason.ProvidedType(typeName)-> String.Format(Strings.GotoDefinitionFailed_ProvidedType(), typeName)
8986
| FSharpFindDeclFailureReason.ProvidedMember(name)-> String.Format(Strings.GotoDefinitionFailed_ProvidedMember(), name)
9087
GotoDefinitionResult_DEPRECATED.MakeError text
88+
| FSharpFindDeclResult.DeclFound mwhen System.IO.File.Exists m.FileName->
89+
letspan= TextSpan(iStartLine= m.StartLine-1, iEndLine= m.StartLine-1, iStartIndex= m.StartColumn, iEndIndex= m.StartColumn)
90+
GotoDefinitionResult_DEPRECATED.MakeSuccess(m.FileName, span)
91+
| FSharpFindDeclResult.DeclFound_(* File does not exist*)->
92+
GotoDefinitionResult_DEPRECATED.MakeError(Strings.GotoDefinitionFailed_NotSourceCode())
9193
| FSharpFindDeclResult.ExternalDecl_->
92-
GotoDefinitionResult_DEPRECATED.MakeError(Strings.GotoDefinitionFailed_NotSourceCode())
94+
GotoDefinitionResult_DEPRECATED.MakeError(Strings.GotoDefinitionFailed_NotSourceCode())
9395
else
9496
Trace.Write("LanguageService","Goto definition: No 'TypeCheckInfo' available")
9597
Strings.GotoDefinitionFailed_NoTypecheckInfo()

‎vsintegration/tests/unittests/LegacyLanguageService/Tests.LanguageService.GotoDefinition.fs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,7 @@ type UsingMSBuild() =
330330
type T = N1.T<"", 1>
331331
""",
332332
marker="T<",
333-
f=(fun(_,result)->
334-
Assert.IsFalse(result.Success)
335-
Assert.That(result.ErrorDescription, Does.Contain("provided type 'T'"))
336-
),
333+
f=(fun(_,result)-> Assert.IsFalse(result.Success)),
337334
addtlRefAssy=[PathRelativeToTestAssembly(@"UnitTests\MockTypeProviders\DummyProviderForLanguageServiceTesting.dll")]
338335
)
339336

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp