Skip to content

Commit 734e8a5

Browse files
authored
Investigate.nuget (#18393)
* initial * testing * temp * Fantomas, readme * temp * nowarn quotes for fantomas * tests
1 parent e92bb80 commit 734e8a5

39 files changed

+373
-72
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,6 @@ positive.exe
134134
/tests/FSharp.Compiler.ComponentTests/FSharpChecker/StandardOutput.txt
135135

136136
# ilverify baseline result files
137-
*.bsl.actual
137+
*.bsl.actual
138+
/src/FSharp.DependencyManager.Nuget/StandardError.txt
139+
/src/FSharp.DependencyManager.Nuget/StandardOutput.txt

docs/release-notes/.FSharp.Compiler.Service/9.0.300.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* Miscellanous parentheses analyzer fixes. ([PR #18350](https://github.com/dotnet/fsharp/pull/18350))
1919
* Fix duplicate parse error reporting for GetBackgroundCheckResultsForFileInProject ([Issue #18379](https://github.com/dotnet/fsharp/issues/18379) [PR #18380](https://github.com/dotnet/fsharp/pull/18380))
2020
* Fix MethodDefNotFound when compiling code invoking delegate with option parameter ([Issue #5171](https://github.com/dotnet/fsharp/issues/5171), [PR #18385](https://github.com/dotnet/fsharp/pull/18385))
21+
* Fix #r nuget ..." downloads unneeded packages ([Issue #18231](https://github.com/dotnet/fsharp/issues/18231), [PR #18393](https://github.com/dotnet/fsharp/pull/18393))
2122

2223
### Added
2324
* Added missing type constraints in FCS. ([PR #18241](https://github.com/dotnet/fsharp/pull/18241))
@@ -30,7 +31,6 @@
3031

3132

3233
### Changed
33-
3434
* FSharpCheckFileResults.ProjectContext.ProjectOptions will not be available when using the experimental Transparent Compiler feature. ([PR #18205](https://github.com/dotnet/fsharp/pull/18205))
3535
* Update `Obsolete` attribute checking to account for `DiagnosticId` and `UrlFormat` properties. ([PR #18224](https://github.com/dotnet/fsharp/pull/18224))
3636
* Remove `Cancellable.UsingToken` from tests ([PR #18276](https://github.com/dotnet/fsharp/pull/18276))

docs/release-notes/.VisualStudio/17.14.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
### Fixed
2+
* Fix #r nuget ..." downloads unneeded packages ([Issue #18231](https://github.com/dotnet/fsharp/issues/18231), [PR #18393](https://github.com/dotnet/fsharp/pull/18393))
23

34
### Added
45
* Add a switch to determine whether to generate a default implementation body for overridden method when completing. [PR #18341](https://github.com/dotnet/fsharp/pull/18341)

src/Compiler/Driver/ScriptClosure.fs

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ type LoadClosure =
4545
/// The resolved package references along with the ranges of the #r positions in each file.
4646
PackageReferences: (range * string list)[]
4747

48+
/// The raw package manager lines in the script
49+
PackageManagerLines: Map<string, PackageManagerLine list>
50+
4851
/// Whether we're decided to use .NET Framework analysis for this script
4952
UseDesktopFramework: bool
5053

@@ -82,7 +85,8 @@ type CodeContext =
8285
module ScriptPreprocessClosure =
8386

8487
/// Represents an input to the closure finding process
85-
type ClosureSource = ClosureSource of fileName: string * referenceRange: range * sourceText: ISourceText * parseRequired: bool
88+
type ClosureSource =
89+
| ClosureSource of fileName: string * referenceRange: range * sourceText: ISourceText * Position option * parseRequired: bool
8690

8791
/// Represents an output of the closure finding process
8892
type ClosureFile =
@@ -253,7 +257,7 @@ module ScriptPreprocessClosure =
253257
| Some(n: int) -> new StreamReader(stream, Encoding.GetEncoding n)
254258

255259
let source = reader.ReadToEnd()
256-
[ ClosureSource(fileName, m, SourceText.ofString source, parseRequired) ]
260+
[ ClosureSource(fileName, m, SourceText.ofString source, None, parseRequired) ]
257261
with RecoverableException exn ->
258262
errorRecovery exn m
259263
[]
@@ -309,16 +313,25 @@ module ScriptPreprocessClosure =
309313
let packageReferences = Dictionary<range, string list>(HashIdentity.Structural)
310314

311315
// Resolve the packages
312-
let rec resolveDependencyManagerSources scriptName =
316+
let rec resolveDependencyManagerSources scriptName (caret: Position option) =
317+
let caretLine =
318+
match caret with
319+
| None -> Int32.MinValue
320+
| Some pos -> pos.Line
321+
322+
let isEditorCursorInPackageLines (line: PackageManagerLine) =
323+
caretLine >= line.Range.StartLine && caretLine <= line.Range.EndLine
324+
313325
[
314326
if not (loadScripts.Contains scriptName) then
315327
for kv in tcConfig.packageManagerLines do
316328
let packageManagerKey, packageManagerLines = kv.Key, kv.Value
317329

318-
match packageManagerLines with
330+
match packageManagerLines |> List.filter (not << isEditorCursorInPackageLines) with
319331
| [] -> ()
320332
| packageManagerLine :: _ ->
321333
let m = packageManagerLine.Range
334+
let packageManagerLines = packageManagerLines
322335
yield! processPackageManagerLines m packageManagerLines scriptName packageManagerKey
323336
]
324337

@@ -422,7 +435,7 @@ module ScriptPreprocessClosure =
422435
let scriptText = stream.ReadAllText()
423436
loadScripts.Add script |> ignore
424437
let iSourceText = SourceText.ofString scriptText
425-
yield! processClosureSource (ClosureSource(script, m, iSourceText, true))
438+
yield! processClosureSource (ClosureSource(script, m, iSourceText, None, true))
426439

427440
else
428441
// Send outputs via diagnostics
@@ -439,7 +452,7 @@ module ScriptPreprocessClosure =
439452
tcConfig <- TcConfig.Create(tcConfigB, validate = false)
440453
]
441454

442-
and processClosureSource (ClosureSource(fileName, m, sourceText, parseRequired)) =
455+
and processClosureSource (ClosureSource(fileName, m, sourceText, caret, parseRequired)) =
443456
[
444457
if not (observedSources.HaveSeen(fileName)) then
445458
observedSources.SetSeen(fileName)
@@ -469,7 +482,7 @@ module ScriptPreprocessClosure =
469482

470483
tcConfig <- tcConfigResult // We accumulate the tcConfig in order to collect assembly references
471484

472-
yield! resolveDependencyManagerSources fileName
485+
yield! resolveDependencyManagerSources fileName caret
473486

474487
let postSources = tcConfig.GetAvailableLoadedSources()
475488

@@ -479,7 +492,7 @@ module ScriptPreprocessClosure =
479492
else
480493
[]
481494

482-
yield! resolveDependencyManagerSources fileName
495+
yield! resolveDependencyManagerSources fileName caret
483496

484497
for m, subFile in sources do
485498
if IsScript subFile then
@@ -536,7 +549,7 @@ module ScriptPreprocessClosure =
536549
| _ -> lastClosureFile
537550

538551
/// Reduce the full directive closure into LoadClosure
539-
let GetLoadClosure (rootFilename, closureFiles, tcConfig: TcConfig, codeContext, packageReferences, earlierDiagnostics) =
552+
let GetLoadClosure (rootFilename, closureFiles, tcConfig: TcConfig, codeContext, packageReferences, earlierDiagnostics) : LoadClosure =
540553

541554
// Mark the last file as isLastCompiland.
542555
let closureFiles =
@@ -608,23 +621,21 @@ module ScriptPreprocessClosure =
608621
// Filter out non-root errors and warnings
609622
let allRootDiagnostics = allRootDiagnostics |> List.filter (fst >> isRootRange)
610623

611-
let result: LoadClosure =
612-
{
613-
SourceFiles = List.groupBy fst sourceFiles |> List.map (map2Of2 (List.map snd))
614-
References = List.groupBy fst references |> List.map (map2Of2 (List.map snd))
615-
PackageReferences = packageReferences
616-
UseDesktopFramework = (tcConfig.primaryAssembly = PrimaryAssembly.Mscorlib)
617-
SdkDirOverride = tcConfig.sdkDirOverride
618-
UnresolvedReferences = unresolvedReferences
619-
Inputs = sourceInputs
620-
NoWarns = List.groupBy fst globalNoWarns |> List.map (map2Of2 (List.map snd))
621-
OriginalLoadReferences = tcConfig.loadedSources
622-
ResolutionDiagnostics = resolutionDiagnostics
623-
AllRootFileDiagnostics = allRootDiagnostics
624-
LoadClosureRootFileDiagnostics = loadClosureRootDiagnostics
625-
}
626-
627-
result
624+
{
625+
SourceFiles = List.groupBy fst sourceFiles |> List.map (map2Of2 (List.map snd))
626+
References = List.groupBy fst references |> List.map (map2Of2 (List.map snd))
627+
PackageReferences = packageReferences
628+
PackageManagerLines = tcConfig.packageManagerLines
629+
UseDesktopFramework = (tcConfig.primaryAssembly = PrimaryAssembly.Mscorlib)
630+
SdkDirOverride = tcConfig.sdkDirOverride
631+
UnresolvedReferences = unresolvedReferences
632+
Inputs = sourceInputs
633+
NoWarns = List.groupBy fst globalNoWarns |> List.map (map2Of2 (List.map snd))
634+
OriginalLoadReferences = tcConfig.loadedSources
635+
ResolutionDiagnostics = resolutionDiagnostics
636+
AllRootFileDiagnostics = allRootDiagnostics
637+
LoadClosureRootFileDiagnostics = loadClosureRootDiagnostics
638+
}
628639

629640
/// Given source text, find the full load closure. Used from service.fs, when editing a script file
630641
let GetFullClosureOfScriptText
@@ -633,6 +644,7 @@ module ScriptPreprocessClosure =
633644
defaultFSharpBinariesDir,
634645
fileName,
635646
sourceText,
647+
caret,
636648
codeContext,
637649
useSimpleResolution,
638650
useFsiAuxLib,
@@ -645,7 +657,6 @@ module ScriptPreprocessClosure =
645657
reduceMemoryUsage,
646658
dependencyProvider
647659
) =
648-
649660
// Resolve the basic references such as FSharp.Core.dll first, before processing any #I directives in the script
650661
//
651662
// This is tries to mimic the action of running the script in F# Interactive - the initial context for scripting is created
@@ -696,7 +707,7 @@ module ScriptPreprocessClosure =
696707
reduceMemoryUsage
697708
)
698709

699-
let closureSources = [ ClosureSource(fileName, range0, sourceText, true) ]
710+
let closureSources = [ ClosureSource(fileName, range0, sourceText, caret, true) ]
700711

701712
let closureFiles, tcConfig, packageReferences =
702713
FindClosureFiles(fileName, closureSources, tcConfig, codeContext, lexResourceManager, dependencyProvider)
@@ -733,6 +744,7 @@ type LoadClosure with
733744
defaultFSharpBinariesDir,
734745
fileName: string,
735746
sourceText: ISourceText,
747+
caret: Position option,
736748
implicitDefines,
737749
useSimpleResolution: bool,
738750
useFsiAuxLib,
@@ -753,6 +765,7 @@ type LoadClosure with
753765
defaultFSharpBinariesDir,
754766
fileName,
755767
sourceText,
768+
caret,
756769
implicitDefines,
757770
useSimpleResolution,
758771
useFsiAuxLib,

src/Compiler/Driver/ScriptClosure.fsi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ type LoadClosure =
4242
/// The resolved package references along with the ranges of the #r positions in each file.
4343
PackageReferences: (range * string list)[]
4444

45+
/// The raw package manager lines in the script
46+
PackageManagerLines: Map<string, PackageManagerLine list>
47+
4548
/// Whether we're decided to use .NET Framework analysis for this script
4649
UseDesktopFramework: bool
4750

@@ -80,6 +83,7 @@ type LoadClosure =
8083
defaultFSharpBinariesDir: string *
8184
fileName: string *
8285
sourceText: ISourceText *
86+
caret: Position option *
8387
implicitDefines: CodeContext *
8488
useSimpleResolution: bool *
8589
useFsiAuxLib: bool *

src/Compiler/Service/BackgroundCompiler.fs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ type internal IBackgroundCompiler =
112112
abstract member GetProjectOptionsFromScript:
113113
fileName: string *
114114
sourceText: ISourceText *
115+
caret: Position option *
115116
previewEnabled: bool option *
116117
loadedTimeStamp: System.DateTime option *
117118
otherFlags: string array option *
@@ -126,6 +127,7 @@ type internal IBackgroundCompiler =
126127
abstract GetProjectSnapshotFromScript:
127128
fileName: string *
128129
sourceText: ISourceTextNew *
130+
caret: Position option *
129131
documentSource: DocumentSource *
130132
previewEnabled: bool option *
131133
loadedTimeStamp: System.DateTime option *
@@ -1276,6 +1278,7 @@ type internal BackgroundCompiler
12761278
(
12771279
fileName,
12781280
sourceText,
1281+
caret,
12791282
previewEnabled,
12801283
loadedTimeStamp,
12811284
otherFlags,
@@ -1326,6 +1329,7 @@ type internal BackgroundCompiler
13261329
FSharpCheckerResultsSettings.defaultFSharpBinariesDir,
13271330
fileName,
13281331
sourceText,
1332+
caret,
13291333
CodeContext.Editing,
13301334
useSimpleResolution,
13311335
useFsiAuxLib,
@@ -1543,6 +1547,7 @@ type internal BackgroundCompiler
15431547
(
15441548
fileName: string,
15451549
sourceText: ISourceText,
1550+
caret: Position option,
15461551
previewEnabled: bool option,
15471552
loadedTimeStamp: DateTime option,
15481553
otherFlags: string array option,
@@ -1556,6 +1561,7 @@ type internal BackgroundCompiler
15561561
self.GetProjectOptionsFromScript(
15571562
fileName,
15581563
sourceText,
1564+
caret,
15591565
previewEnabled,
15601566
loadedTimeStamp,
15611567
otherFlags,
@@ -1571,6 +1577,7 @@ type internal BackgroundCompiler
15711577
(
15721578
fileName: string,
15731579
sourceText: ISourceTextNew,
1580+
caret: Position option,
15741581
documentSource: DocumentSource,
15751582
previewEnabled: bool option,
15761583
loadedTimeStamp: DateTime option,
@@ -1587,6 +1594,7 @@ type internal BackgroundCompiler
15871594
self.GetProjectOptionsFromScript(
15881595
fileName,
15891596
sourceText,
1597+
caret,
15901598
previewEnabled,
15911599
loadedTimeStamp,
15921600
otherFlags,

src/Compiler/Service/BackgroundCompiler.fsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ type internal IBackgroundCompiler =
9090
abstract GetProjectOptionsFromScript:
9191
fileName: string *
9292
sourceText: ISourceText *
93+
caret: Position option *
9394
previewEnabled: bool option *
9495
loadedTimeStamp: System.DateTime option *
9596
otherFlags: string array option *
@@ -104,6 +105,7 @@ type internal IBackgroundCompiler =
104105
abstract GetProjectSnapshotFromScript:
105106
fileName: string *
106107
sourceText: ISourceTextNew *
108+
caret: Position option *
107109
documentSource: DocumentSource *
108110
previewEnabled: bool option *
109111
loadedTimeStamp: System.DateTime option *

src/Compiler/Service/FSharpCheckerResults.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3981,6 +3981,7 @@ type FsiInteractiveChecker(legacyReferenceResolver, tcConfig: TcConfig, tcGlobal
39813981
defaultFSharpBinariesDir,
39823982
fileName,
39833983
sourceText,
3984+
None,
39843985
CodeContext.Editing,
39853986
tcConfig.useSimpleResolution,
39863987
tcConfig.useFsiAuxLib,

src/Compiler/Service/TransparentCompiler.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ type internal TransparentCompiler
496496
defaultFSharpBinariesDir,
497497
fileName,
498498
source,
499+
None,
499500
CodeContext.Editing,
500501
useSimpleResolution,
501502
useFsiAuxLib,
@@ -2315,6 +2316,7 @@ type internal TransparentCompiler
23152316
(
23162317
fileName: string,
23172318
sourceText: ISourceText,
2319+
caret: Position option,
23182320
previewEnabled: bool option,
23192321
loadedTimeStamp: DateTime option,
23202322
otherFlags: string array option,
@@ -2332,6 +2334,7 @@ type internal TransparentCompiler
23322334
bc.GetProjectSnapshotFromScript(
23332335
fileName,
23342336
SourceTextNew.ofISourceText sourceText,
2337+
caret,
23352338
DocumentSource.FileSystem,
23362339
previewEnabled,
23372340
loadedTimeStamp,
@@ -2352,6 +2355,7 @@ type internal TransparentCompiler
23522355
(
23532356
fileName: string,
23542357
sourceText: ISourceTextNew,
2358+
caret: Position option,
23552359
documentSource: DocumentSource,
23562360
previewEnabled: bool option,
23572361
loadedTimeStamp: DateTime option,

src/Compiler/Service/service.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ type FSharpChecker
492492
(
493493
fileName,
494494
source,
495+
?caret,
495496
?previewEnabled,
496497
?loadedTimeStamp,
497498
?otherFlags,
@@ -507,6 +508,7 @@ type FSharpChecker
507508
backgroundCompiler.GetProjectOptionsFromScript(
508509
fileName,
509510
source,
511+
caret,
510512
previewEnabled,
511513
loadedTimeStamp,
512514
otherFlags,
@@ -523,6 +525,7 @@ type FSharpChecker
523525
(
524526
fileName,
525527
source,
528+
?caret,
526529
?documentSource,
527530
?previewEnabled,
528531
?loadedTimeStamp,
@@ -540,6 +543,7 @@ type FSharpChecker
540543
backgroundCompiler.GetProjectSnapshotFromScript(
541544
fileName,
542545
source,
546+
caret,
543547
documentSource,
544548
previewEnabled,
545549
loadedTimeStamp,

0 commit comments

Comments
 (0)