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

Commit5a12cde

Browse files
auduchinokKevinRansom
authored andcommitted
Add IsInteractive to parsing options for script load closures (#4169)
* Add IsInteractive to FSharpParsingOptions* Add test
1 parentc46ca4e commit5a12cde

File tree

18 files changed

+95
-52
lines changed

18 files changed

+95
-52
lines changed

‎src/fsharp/service/ServiceUntypedParse.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ module SourceFileImpl =
4141
0= String.Compare(".fsi",ext,StringComparison.OrdinalIgnoreCase)
4242

4343
/// Additional #defines that should be in place when editing a file in a file editor such as VS.
44-
letAdditionalDefinesForUseInEditor(filename)=
45-
ifCompileOps.IsScript(filename)then["INTERACTIVE";"EDITING"]// This is still used by the foreground parse
44+
letAdditionalDefinesForUseInEditor(isInteractive:bool)=
45+
ifisInteractivethen["INTERACTIVE";"EDITING"]// This is still used by the foreground parse
4646
else["COMPILED";"EDITING"]
4747

4848
typeCompletionPath= string list* string option// plid * residue

‎src/fsharp/service/ServiceUntypedParse.fsi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,5 @@ module public UntypedParseImpl =
112112
// implementation details used by other code in the compiler
113113
module internal SourceFileImpl=
114114
valIsInterfaceFile:string->bool
115-
valAdditionalDefinesForUseInEditor:string->string list
115+
valAdditionalDefinesForUseInEditor:isInteractive:bool->string list
116116

‎src/fsharp/service/service.fs‎

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,14 +1394,13 @@ type TypeCheckInfo
13941394
override__.ToString()="TypeCheckInfo("+ mainInputFileName+")"
13951395

13961396
typeFSharpParsingOptions=
1397-
{
1398-
SourceFiles:string[]
1397+
{ SourceFiles:string[]
13991398
ConditionalCompilationDefines:string list
14001399
ErrorSeverityOptions:FSharpErrorSeverityOptions
1400+
IsInteractive:bool
14011401
LightSyntax:bool option
14021402
CompilingFsLib:bool
1403-
IsExe:bool
1404-
}
1403+
IsExe:bool}
14051404

14061405
memberx.LastFileName=
14071406
Debug.Assert(not(Array.isEmpty x.SourceFiles),"Parsing options don't contain any file")
@@ -1411,26 +1410,26 @@ type FSharpParsingOptions =
14111410
{ SourceFiles= Array.empty
14121411
ConditionalCompilationDefines=[]
14131412
ErrorSeverityOptions= FSharpErrorSeverityOptions.Default
1413+
IsInteractive=false
14141414
LightSyntax= None
14151415
CompilingFsLib=false
1416-
IsExe=false
1417-
}
1416+
IsExe=false}
14181417

1419-
static memberFromTcConfig(tcConfig:TcConfig,sourceFiles)=
1420-
{
1421-
SourceFiles= sourceFiles
1418+
static memberFromTcConfig(tcConfig:TcConfig,sourceFiles,isInteractive:bool)=
1419+
{ SourceFiles= sourceFiles
14221420
ConditionalCompilationDefines= tcConfig.conditionalCompilationDefines
14231421
ErrorSeverityOptions= tcConfig.errorSeverityOptions
1422+
IsInteractive= isInteractive
14241423
LightSyntax= tcConfig.light
14251424
CompilingFsLib= tcConfig.compilingFslib
1426-
IsExe= tcConfig.target.IsExe
1427-
}
1425+
IsExe= tcConfig.target.IsExe}
14281426

1429-
static memberFromTcConfigBuidler(tcConfigB:TcConfigBuilder,sourceFiles)=
1427+
static memberFromTcConfigBuidler(tcConfigB:TcConfigBuilder,sourceFiles,isInteractive:bool)=
14301428
{
14311429
SourceFiles= sourceFiles
14321430
ConditionalCompilationDefines= tcConfigB.conditionalCompilationDefines
14331431
ErrorSeverityOptions= tcConfigB.errorSeverityOptions
1432+
IsInteractive= isInteractive
14341433
LightSyntax= tcConfigB.light
14351434
CompilingFsLib= tcConfigB.compilingFslib
14361435
IsExe= tcConfigB.target.IsExe
@@ -1502,7 +1501,7 @@ module internal Parser =
15021501

15031502
// If we're editing a script then we define INTERACTIVE otherwise COMPILED.
15041503
// Since this parsing for intellisense we always define EDITING.
1505-
letdefines= SourceFileImpl.AdditionalDefinesForUseInEditor(fileName)@ options.ConditionalCompilationDefines
1504+
letdefines=(SourceFileImpl.AdditionalDefinesForUseInEditor options.IsInteractive)@ options.ConditionalCompilationDefines
15061505

15071506
// Note: we don't really attempt to intern strings across a large scope.
15081507
letlexResourceManager=new Lexhelp.LexResourceManager()
@@ -2520,7 +2519,7 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
25202519
let!tcErrors,tcFileResult=
25212520
Parser.CheckOneFile(parseResults, source, fileName, options.ProjectFileName, tcPrior.TcConfig, tcPrior.TcGlobals, tcPrior.TcImports,
25222521
tcPrior.TcState, loadClosure, tcPrior.Errors, reactorOps,(fun()-> builder.IsAlive), textSnapshotInfo, userOpName)
2523-
letparsingOptions= FSharpParsingOptions.FromTcConfig(tcPrior.TcConfig, Array.ofList builder.SourceFiles)
2522+
letparsingOptions= FSharpParsingOptions.FromTcConfig(tcPrior.TcConfig, Array.ofList builder.SourceFiles, options.UseScriptResolutionRules)
25242523
letcheckAnswer= MakeCheckFileAnswer(fileName, tcFileResult, options, builder, Array.ofList tcPrior.TcDependencyFiles, creationErrors, parseResults.Errors, tcErrors)
25252524
bc.RecordTypeCheckFileInProjectResults(fileName, options, parsingOptions, parseResults, fileVersion, tcPrior.TimeStamp, Some checkAnswer, source)
25262525
return checkAnswer
@@ -2634,7 +2633,7 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
26342633
let!tcPrior= execWithReactorAsync<|fun ctok-> builder.GetCheckResultsBeforeFileInProject(ctok, filename)
26352634

26362635
// Do the parsing.
2637-
letparsingOptions= FSharpParsingOptions.FromTcConfig(builder.TcConfig, Array.ofList(builder.SourceFiles))
2636+
letparsingOptions= FSharpParsingOptions.FromTcConfig(builder.TcConfig, Array.ofList(builder.SourceFiles), options.UseScriptResolutionRules)
26382637
letparseErrors,parseTreeOpt,anyErrors= Parser.parseFile(source, filename, parsingOptions, userOpName)
26392638
letparseTreeOpt= parseTreeOpt|> Option.map builder.DeduplicateParsedInputModuleNameInProject
26402639
letparseResults= FSharpParseFileResults(parseErrors, parseTreeOpt, anyErrors, builder.AllDependenciesDeprecated)
@@ -2914,7 +2913,7 @@ type FSharpChecker(legacyReferenceResolver, projectCacheSize, keepAssemblyConten
29142913
memberic.GetParsingOptionsFromProjectOptions(options):FSharpParsingOptions* _=
29152914
letsourceFiles= List.ofArray options.SourceFiles
29162915
letargv= List.ofArray options.OtherOptions
2917-
ic.GetParsingOptionsFromCommandLineArgs(sourceFiles, argv)
2916+
ic.GetParsingOptionsFromCommandLineArgs(sourceFiles, argv, options.UseScriptResolutionRules)
29182917

29192918
memberic.MatchBraces(filename,source,options:FSharpProjectOptions,?userOpName:string)=
29202919
letuserOpName= defaultArg userOpName"Unknown"
@@ -3117,16 +3116,17 @@ type FSharpChecker(legacyReferenceResolver, projectCacheSize, keepAssemblyConten
31173116
ExtraProjectInfo=extraProjectInfo
31183117
Stamp= None}
31193118

3120-
memberic.GetParsingOptionsFromCommandLineArgs(initialSourceFiles,argv)=
3119+
memberic.GetParsingOptionsFromCommandLineArgs(initialSourceFiles,argv,?isInteractive)=
3120+
letisInteractive= defaultArg isInteractivefalse
31213121
use errorScope=new ErrorScope()
31223122
lettcConfigBuilder= TcConfigBuilder.Initial
31233123

31243124
// Apply command-line arguments and collect more source files if they are in the arguments
31253125
letsourceFilesNew= ApplyCommandLineArgs(tcConfigBuilder, initialSourceFiles, argv)
3126-
FSharpParsingOptions.FromTcConfigBuidler(tcConfigBuilder, Array.ofList sourceFilesNew), errorScope.Diagnostics
3126+
FSharpParsingOptions.FromTcConfigBuidler(tcConfigBuilder, Array.ofList sourceFilesNew, isInteractive), errorScope.Diagnostics
31273127

3128-
memberic.GetParsingOptionsFromCommandLineArgs(argv)=
3129-
ic.GetParsingOptionsFromCommandLineArgs([], argv)
3128+
memberic.GetParsingOptionsFromCommandLineArgs(argv,?isInteractive:bool)=
3129+
ic.GetParsingOptionsFromCommandLineArgs([], argv, ?isInteractive=isInteractive)
31303130

31313131
/// Begin background parsing the given project.
31323132
memberic.StartBackgroundCompile(options,?userOpName)=
@@ -3197,7 +3197,7 @@ type FsiInteractiveChecker(legacyReferenceResolver, reactorOps: IReactorOperatio
31973197
letuserOpName= defaultArg userOpName"Unknown"
31983198
letfilename= Path.Combine(tcConfig.implicitIncludeDir,"stdin.fsx")
31993199
// Note: projectSourceFiles is only used to compute isLastCompiland, and is ignored if Build.IsScript(mainInputFileName) is true (which it is in this case).
3200-
letparsingOptions= FSharpParsingOptions.FromTcConfig(tcConfig,[| filename|])
3200+
letparsingOptions= FSharpParsingOptions.FromTcConfig(tcConfig,[| filename|],true)
32013201
letparseErrors,parseTreeOpt,anyErrors= Parser.parseFile(source, filename, parsingOptions, userOpName)
32023202
letdependencyFiles=[||]// interactions have no dependencies
32033203
letparseResults= FSharpParseFileResults(parseErrors, parseTreeOpt, parseHadErrors= anyErrors, dependencyFiles= dependencyFiles)
@@ -3240,8 +3240,8 @@ module CompilerEnvironment =
32403240
letDefaultReferencesForOrphanSources(assumeDotNetFramework)= DefaultReferencesForScriptsAndOutOfProjectSources(assumeDotNetFramework)
32413241

32423242
/// Publish compiler-flags parsing logic. Must be fast because its used by the colorizer.
3243-
letGetCompilationDefinesForEditing(filename:string,parsingOptions:FSharpParsingOptions)=
3244-
SourceFileImpl.AdditionalDefinesForUseInEditor(filename)@
3243+
letGetCompilationDefinesForEditing(parsingOptions:FSharpParsingOptions)=
3244+
SourceFileImpl.AdditionalDefinesForUseInEditor(parsingOptions.IsInteractive)@
32453245
parsingOptions.ConditionalCompilationDefines
32463246

32473247
/// Return true if this is a subcategory of error or warning message that the language service can emit

‎src/fsharp/service/service.fsi‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ type public FSharpParsingOptions =
295295
SourceFiles:string[]
296296
ConditionalCompilationDefines:string list
297297
ErrorSeverityOptions:FSharpErrorSeverityOptions
298+
IsInteractive:bool
298299
LightSyntax:bool option
299300
CompilingFsLib:bool
300301
IsExe:bool
@@ -533,14 +534,14 @@ type public FSharpChecker =
533534
///
534535
///<param name="sourceFiles">Initial source files list. Additional files may be added during argv evaluation.</param>
535536
/// <param name="argv">The command line arguments for the project build.</param>
536-
memberGetParsingOptionsFromCommandLineArgs:sourceFiles:string list* argv: string list-> FSharpParsingOptions* FSharpErrorInfo list
537+
memberGetParsingOptionsFromCommandLineArgs:sourceFiles:string list* argv: string list* ?isInteractive: bool-> FSharpParsingOptions* FSharpErrorInfo list
537538

538539
///<summary>
539540
///<para>Get the FSharpParsingOptions implied by a set of command line arguments.</para>
540541
///</summary>
541542
///
542543
///<param name="argv">The command line argumentsfor the project build.</param>
543-
memberGetParsingOptionsFromCommandLineArgs:argv:string list->FSharpParsingOptions* FSharpErrorInfo list
544+
memberGetParsingOptionsFromCommandLineArgs:argv:string list* ?isInteractive: bool-> FSharpParsingOptions* FSharpErrorInfo list
544545

545546
///<summary>
546547
///<para>Get the FSharpParsingOptions implied by a FSharpProjectOptions.</para>
@@ -727,11 +728,11 @@ type public CompilerEnvironment =
727728
module public CompilerEnvironment=
728729
/// These are the names of assemblies that should be referenced for .fs or .fsi files that
729730
/// are not associated with a project.
730-
valDefaultReferencesForOrphanSources:assumeDotNetFramework:bool->string list
731+
valDefaultReferencesForOrphanSources:assumeDotNetFramework:bool->string list
731732
/// Return the compilation defines that should be used when editing the given file.
732-
valGetCompilationDefinesForEditing:filename:string*parsingOptions: FSharpParsingOptions-> string list
733+
valGetCompilationDefinesForEditing:parsingOptions:FSharpParsingOptions->string list
733734
/// Return true if this is a subcategory of error or warning message that the language service can emit
734-
val IsCheckerSupportedSubcategory: string-> bool
735+
valIsCheckerSupportedSubcategory:string->bool
735736

736737
/// Information about the debugging environment
737738
modulepublicDebuggerEnvironment=

‎tests/service/ProjectOptionsTests.fs‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ open System
1414
openSystem.IO
1515
openNUnit.Framework
1616
openFsUnit
17+
openMicrosoft.FSharp.Compiler.Ast
1718
openMicrosoft.FSharp.Compiler.SourceCodeServices
1819

1920
openFSharp.Compiler.Service.Tests.Common
@@ -518,6 +519,46 @@ let ``Test SourceFiles order for GetProjectOptionsFromScript`` () = // See #594
518519
test"Main4"[|"BaseLib2";"Lib5";"BaseLib1";"Lib1";"Lib2";"Main4"|]
519520
test"MainBad"[|"MainBad"|]
520521

522+
[<Test>]
523+
let``Script load closure project``()=
524+
letfileName1= Path.GetTempPath()+ Path.DirectorySeparatorChar.ToString()+"Impl.fs"
525+
letfileName2= Path.ChangeExtension(Path.GetTempFileName(),".fsx")
521526

527+
letfileSource1="""
528+
module ImplFile
522529
523-
530+
#if INTERACTIVE
531+
let x = 42
532+
#endif
533+
"""
534+
535+
letfileSource2="""
536+
#load "Impl.fs"
537+
ImplFile.x
538+
"""
539+
540+
File.WriteAllText(fileName1, fileSource1)
541+
File.WriteAllText(fileName2, fileSource2)
542+
543+
letprojectOptions,diagnostics=
544+
checker.GetProjectOptionsFromScript(fileName2, fileSource2)|> Async.RunSynchronously
545+
diagnostics.IsEmpty|> shouldEqualtrue
546+
547+
let_,checkResults=
548+
checker.ParseAndCheckFileInProject(fileName2,0, fileSource2, projectOptions)|> Async.RunSynchronously
549+
550+
match checkResultswith
551+
| FSharpCheckFileAnswer.Succeeded results->
552+
results.Errors|> shouldEqual[||]
553+
|_-> failwith"type check was aborted"
554+
555+
letparsingOptions,diagnostics= checker.GetParsingOptionsFromProjectOptions(projectOptions)
556+
diagnostics.IsEmpty|> shouldEqualtrue
557+
558+
letparseResults= checker.ParseFile(fileName1, fileSource1, parsingOptions)|> Async.RunSynchronously
559+
parseResults.ParseTree.IsSome|> shouldEqualtrue
560+
match parseResults.ParseTree.Valuewith
561+
| ParsedInput.ImplFile(ParsedImplFileInput(_,_,_,_,_, modules,_))->
562+
let(SynModuleOrNamespace(_,_,_,decls,_,_,_,_))= modules.Head
563+
decls.Length|> shouldEqual1
564+
|_-> failwith"got sig file"

‎vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ type internal FSharpAddOpenCodeFixProvider
101101
let!_,parsedInput,checkResults= checker.ParseAndCheckDocument(document, projectOptions, allowStaleResults=true, sourceText= sourceText, userOpName= userOpName)
102102
letline= sourceText.Lines.GetLineFromPosition(context.Span.End)
103103
letlinePos= sourceText.Lines.GetLinePosition(context.Span.End)
104-
letdefines= CompilerEnvironment.GetCompilationDefinesForEditing(document.Name, parsingOptions)
104+
letdefines= CompilerEnvironment.GetCompilationDefinesForEditing parsingOptions
105105

106106
let!symbol=
107107
asyncMaybe{

‎vsintegration/src/FSharp.Editor/CodeFix/ImplementInterfaceCodeFixProvider.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ type internal FSharpImplementInterfaceCodeFixProvider
144144
let!sourceText= context.Document.GetTextAsync(cancellationToken)
145145
let!_,parsedInput,checkFileResults= checker.ParseAndCheckDocument(context.Document, projectOptions, sourceText= sourceText, allowStaleResults=true, userOpName= userOpName)
146146
lettextLine= sourceText.Lines.GetLineFromPosition context.Span.Start
147-
letdefines= CompilerEnvironment.GetCompilationDefinesForEditing(context.Document.FilePath, parsingOptions)
147+
letdefines= CompilerEnvironment.GetCompilationDefinesForEditing parsingOptions
148148
// Notice that context.Span doesn't return reliable ranges to find tokens at exact positions.
149149
// That's why we tokenize the line and try to find the last successive identifier token
150150
lettokens= Tokenizer.tokenizeLine(context.Document.Id, sourceText, context.Span.Start, context.Document.FilePath, defines)

‎vsintegration/src/FSharp.Editor/CodeFix/RenameUnusedValue.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type internal FSharpRenameUnusedValueCodeFixProvider
6060
let!parsingOptions,projectOptions= projectInfoManager.TryGetOptionsForEditingDocumentOrProject document
6161
let!_,_,checkResults= checker.ParseAndCheckDocument(document, projectOptions, allowStaleResults=true, sourceText= sourceText, userOpName=userOpName)
6262
letm= RoslynHelpers.TextSpanToFSharpRange(document.FilePath, context.Span, sourceText)
63-
letdefines= CompilerEnvironment.GetCompilationDefinesForEditing(document.FilePath,parsingOptions)
63+
letdefines= CompilerEnvironment.GetCompilationDefinesForEditing parsingOptions
6464
let!lexerSymbol= Tokenizer.getSymbolAtPosition(document.Id, sourceText, context.Span.Start, document.FilePath, defines, SymbolLookupKind.Greedy,false)
6565
letlineText=(sourceText.Lines.GetLineFromPosition context.Span.Start).ToString()
6666
let!symbolUse= checkResults.GetSymbolUseAtLocation(m.StartLine, m.EndColumn, lineText, lexerSymbol.FullIsland, userOpName=userOpName)

‎vsintegration/src/FSharp.Editor/DocumentHighlights/DocumentHighlightsService.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type internal FSharpDocumentHighlightsService [<ImportingConstructor>] (checkerP
7979
let!parsingOptions,projectOptions= projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
8080
let!sourceText= document.GetTextAsync(cancellationToken)
8181
let!textVersion= document.GetTextVersionAsync(cancellationToken)
82-
letdefines= CompilerEnvironment.GetCompilationDefinesForEditing(document.Name, parsingOptions)
82+
letdefines= CompilerEnvironment.GetCompilationDefinesForEditing parsingOptions
8383
let!spans= FSharpDocumentHighlightsService.GetDocumentHighlights(checkerProvider.Checker, document.Id, sourceText, document.FilePath,
8484
position, defines, projectOptions, textVersion.GetHashCode())
8585
lethighlightSpans=

‎vsintegration/src/FSharp.Editor/Formatting/EditorFormattingService.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type internal FSharpEditorFormattingService
3838

3939
letline= sourceText.Lines.[sourceText.Lines.IndexOf position]
4040

41-
letdefines= CompilerEnvironment.GetCompilationDefinesForEditing(filePath, parsingOptions)
41+
letdefines= CompilerEnvironment.GetCompilationDefinesForEditing parsingOptions
4242

4343
lettokens= Tokenizer.tokenizeLine(documentId, sourceText, line.Start, filePath, defines)
4444

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp