Skip to content

Commit

Permalink
merge from main to get up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel committed Aug 21, 2023
2 parents 9553a7f + 452411b commit 5be7315
Show file tree
Hide file tree
Showing 12 changed files with 844 additions and 554 deletions.
44 changes: 22 additions & 22 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"FSharp.excludeProjectDirectories": [
".git",
"paket-files",
"packages",
"test/FsAutoComplete.IntegrationTests"
],
//otherwise take a lot of time to load proj inside
//the test directories
"omnisharp.autoStart": false,
"FSharp.minimizeBackgroundParsing": true,
"FSharp.trace.server": "verbose",
"yaml.schemas": {
"https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/github-workflow.json": ".github/workflows/*"
},
"editor.inlayHints.enabled": "offUnlessPressed",
"FSharp.enableAdaptiveLspServer": true,
"files.associations": {
"*.*proj": "msbuild",
"*.props": "msbuild",
"*.targets": "msbuild"
}
}
"FSharp.excludeProjectDirectories": [
".git",
"paket-files",
"packages",
"test/FsAutoComplete.IntegrationTests"
],
//otherwise take a lot of time to load proj inside
//the test directories
"omnisharp.autoStart": false,
"FSharp.minimizeBackgroundParsing": true,
"FSharp.trace.server": "off",
"yaml.schemas": {
"https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/github-workflow.json": ".github/workflows/*"
},
"editor.inlayHints.enabled": "offUnlessPressed",
"FSharp.enableAdaptiveLspServer": true,
"files.associations": {
"*.*proj": "msbuild",
"*.props": "msbuild",
"*.targets": "msbuild"
}
}
8 changes: 4 additions & 4 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ lowest_matching: true
nuget BenchmarkDotNet 0.13.5
nuget Fantomas.Client >= 0.9
nuget FSharp.Compiler.Service >= 43.7.400
nuget Ionide.ProjInfo >= 0.61.3
nuget Ionide.ProjInfo.FCS >= 0.61.3
nuget Ionide.ProjInfo.ProjectSystem >= 0.61.3
nuget Ionide.ProjInfo.Sln >= 0.61.3
nuget Ionide.ProjInfo >= 0.62.0
nuget Ionide.ProjInfo.FCS >= 0.62.0
nuget Ionide.ProjInfo.ProjectSystem >= 0.62.0
nuget Ionide.ProjInfo.Sln >= 0.62.0
nuget Microsoft.Build >= 17.2 copy_local:false
nuget Microsoft.Build.Framework >= 17.4 copy_local:false
nuget Microsoft.Build.Utilities.Core >= 17.4 copy_local:false
Expand Down
28 changes: 14 additions & 14 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,25 @@ NUGET
FSharp.Core (>= 6.0)
Newtonsoft.Json (>= 13.0.1)
StreamJsonRpc (>= 2.10.44)
Ionide.ProjInfo (0.62.0-nightly001)
FSharp.Core (>= 7.0.400-beta.23322.4 < 7.1.0-prerelease) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Ionide.ProjInfo.Sln (>= 0.62.0-nightly001) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Ionide.ProjInfo (0.62)
FSharp.Core (>= 7.0.400) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Ionide.ProjInfo.Sln (>= 0.62) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Microsoft.Build (>= 17.2) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Microsoft.Build.Framework (>= 17.6.3) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
SemanticVersioning (>= 2.0.2) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Ionide.ProjInfo.FCS (0.62.0-nightly001)
FSharp.Compiler.Service (>= 43.7.400-preview.23322.4 < 43.8.0-prerelease) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
FSharp.Core (>= 7.0.400-beta.23322.4 < 7.1.0-prerelease) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Ionide.ProjInfo (>= 0.62.0-nightly001) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Ionide.ProjInfo.ProjectSystem (0.62.0-nightly001)
FSharp.Compiler.Service (>= 43.7.400-preview.23322.4 < 43.8.0-prerelease) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Ionide.ProjInfo.FCS (0.62)
FSharp.Compiler.Service (>= 43.7.400) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
FSharp.Core (>= 7.0.400) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Ionide.ProjInfo (>= 0.62) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Ionide.ProjInfo.ProjectSystem (0.62)
FSharp.Compiler.Service (>= 43.7.400) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
FSharp.Control.Reactive (>= 5.0.5) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
FSharp.Core (>= 7.0.400-beta.23322.4 < 7.1.0-prerelease) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Ionide.ProjInfo (>= 0.62.0-nightly001) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Ionide.ProjInfo.FCS (>= 0.62.0-nightly001) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Ionide.ProjInfo.Sln (>= 0.62.0-nightly001) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
FSharp.Core (>= 7.0.400) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Ionide.ProjInfo (>= 0.62) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Ionide.ProjInfo.FCS (>= 0.62) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Ionide.ProjInfo.Sln (>= 0.62) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Newtonsoft.Json (>= 13.0.1) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0)) (&& (== netstandard2.1) (>= net6.0))
Ionide.ProjInfo.Sln (0.61.3)
Ionide.ProjInfo.Sln (0.62)
LinkDotNet.StringBuilder (1.18)
McMaster.NETCore.Plugins (1.4) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net5.0)) (&& (== netstandard2.1) (>= net5.0))
Microsoft.DotNet.PlatformAbstractions (>= 3.1.6) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= netcoreapp2.1)) (&& (== netstandard2.1) (>= netcoreapp2.1))
Expand Down
11 changes: 5 additions & 6 deletions src/FsAutoComplete.Core/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,6 @@ module Commands =
return (symbol, dict)
}


/// * `includeDeclarations`:
/// if `false` only returns usage locations and excludes declarations
/// * Note: if `true` you can still separate usages and declarations from each other
Expand Down Expand Up @@ -2048,7 +2047,7 @@ type Commands
match valData with
| SynValData(memberFlags = Some({ MemberKind = SynMemberKind.PropertyGet }))
| SynValData(memberFlags = Some({ MemberKind = SynMemberKind.PropertySet }))
| SynValData(memberFlags = Some({ MemberKind = SynMemberKind.PropertyGetSet })) -> Some true
| SynValData(memberFlags = Some({ MemberKind = SynMemberKind.PropertyGetSet })) -> None
| _ -> Some false
| _ -> defaultTraverse synBinding

Expand Down Expand Up @@ -2145,17 +2144,17 @@ type Commands
->
Some true
| SynMemberDefn.GetSetMember(
memberDefnForGet = Some(SynBinding(
memberDefnForSet = Some(SynBinding(
xmlDoc = xmlDoc; headPat = SynPat.LongIdent(longDotId = longDotId)))) when
rangeContainsPos longDotId.Range pos && xmlDoc.IsEmpty
->
Some true
Some false
| SynMemberDefn.GetSetMember(
memberDefnForSet = Some(SynBinding(
memberDefnForGet = Some(SynBinding(
xmlDoc = xmlDoc; headPat = SynPat.LongIdent(longDotId = longDotId)))) when
rangeContainsPos longDotId.Range pos && xmlDoc.IsEmpty
->
Some true
Some false
| _ -> None)
| _ -> None)
| _ -> None)
Expand Down
13 changes: 7 additions & 6 deletions src/FsAutoComplete.Core/CompilerServiceInterface.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ open FsToolkit.ErrorHandling

type Version = int

type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize) =
type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize, parallelReferenceResolution) =
let checker =
FSharpChecker.Create(
projectCacheSize = 200,
keepAllBackgroundResolutions = true,
keepAssemblyContents = hasAnalyzers,
keepAllBackgroundResolutions = true,
suggestNamesForErrors = true,
enablePartialTypeChecking = not hasAnalyzers,
keepAllBackgroundSymbolUses = true,
enableBackgroundItemKeyStoreAndSemanticClassification = true,
keepAllBackgroundSymbolUses = true
enablePartialTypeChecking = not hasAnalyzers,
parallelReferenceResolution = parallelReferenceResolution,
captureIdentifiersWhenParsing = true,
useSyntaxTreeCache = true
)



let entityCache = EntityCache()

// This is used to hold previous check results for autocompletion.
Expand Down
4 changes: 3 additions & 1 deletion src/FsAutoComplete.Core/CompilerServiceInterface.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ open FsToolkit.ErrorHandling
type Version = int

type FSharpCompilerServiceChecker =
new: hasAnalyzers: bool * typecheckCacheSize: int64 -> FSharpCompilerServiceChecker
new:
hasAnalyzers: bool * typecheckCacheSize: int64 * parallelReferenceResolution: bool -> FSharpCompilerServiceChecker

member DisableInMemoryProjectReferences: bool with get, set

static member GetDependingProjects:
Expand Down
39 changes: 26 additions & 13 deletions src/FsAutoComplete.Core/Lexer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,35 @@ type private DraftToken =
module Lexer =
let logger = LogProvider.getLoggerByName "Lexer"

[<return: Struct>]
let (|Define|_|) (a: string) =
if a.StartsWith "--defin:" then
ValueSome(a.[9..])
else
ValueNone

[<return: Struct>]
let (|LangVersion|_|) (a: string) =
if a.StartsWith "--langversion:" then
ValueSome(a.[14..])
else
ValueNone

/// Return all tokens of current line
let tokenizeLine (args: string[]) lineStr =
let defines =
args
|> Seq.choose (fun s -> if s.StartsWith "--define:" then Some s.[9..] else None)
|> Seq.toList

let langVersion =
args
|> Array.tryPick (fun arg ->
if arg.StartsWith "--langversion:" then
Some(arg.[14..])
else
None)
let defines, langVersion =
((ResizeArray(), None), args)
||> Array.fold (fun (defines, langVersion) arg ->
match arg with
| Define d ->
defines.Add(d)
defines, langVersion
| LangVersion v -> defines, Some(v)
| _ -> defines, langVersion)

let sourceTokenizer =
FSharpSourceTokenizer(Seq.toList defines, Some "/tmp.fsx", langVersion)

let sourceTokenizer = FSharpSourceTokenizer(defines, Some "/tmp.fsx", langVersion)
let lineTokenizer = sourceTokenizer.CreateLineTokenizer lineStr

let rec loop lexState acc =
Expand Down
14 changes: 11 additions & 3 deletions src/FsAutoComplete/LspHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ type FSACDto =
{
/// <summary>The <see cref='F:Microsoft.Extensions.Caching.Memory.MemoryCacheOptions.SizeLimit '/> for typecheck cache. </summary>
CachedTypeCheckCount: int64 option
ParallelReferenceResolution: bool option
}

type FSharpConfigDto =
Expand Down Expand Up @@ -728,16 +729,23 @@ type FSACConfig =
{
/// <summary>The <see cref='F:Microsoft.Extensions.Caching.Memory.MemoryCacheOptions.SizeLimit '/> for typecheck cache. </summary>
CachedTypeCheckCount: int64
/// <summary>Whether to use parallel reference resolution in the compiler. See <see href="https://fsharp.github.io/fsharp-compiler-docs/reference/fsharp-compiler-codeanalysis-fsharpchecker.html#Create">the docs</see> for details.</summary>
ParallelReferenceResolution: bool
}

static member Default = { CachedTypeCheckCount = 200L }
static member Default =
{ CachedTypeCheckCount = 200L
ParallelReferenceResolution = true }

static member FromDto(dto: FSACDto) =
let defaultConfig = FSACConfig.Default
{ CachedTypeCheckCount = defaultArg dto.CachedTypeCheckCount defaultConfig.CachedTypeCheckCount }

{ CachedTypeCheckCount = defaultArg dto.CachedTypeCheckCount defaultConfig.CachedTypeCheckCount
ParallelReferenceResolution = defaultArg dto.ParallelReferenceResolution defaultConfig.ParallelReferenceResolution }

member this.AddDto(dto: FSACDto) =
{ CachedTypeCheckCount = defaultArg dto.CachedTypeCheckCount this.CachedTypeCheckCount }
{ CachedTypeCheckCount = defaultArg dto.CachedTypeCheckCount this.CachedTypeCheckCount
ParallelReferenceResolution = defaultArg dto.ParallelReferenceResolution this.ParallelReferenceResolution }

type DebugConfig =
{ DontCheckRelatedFiles: bool
Expand Down
3 changes: 3 additions & 0 deletions src/FsAutoComplete/LspHelpers.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ type FSACDto =
{
/// <summary>The <see cref='F:Microsoft.Extensions.Caching.Memory.MemoryCacheOptions.SizeLimit '/> for typecheck cache. </summary>
CachedTypeCheckCount: int64 option
ParallelReferenceResolution: bool option
}

type FSharpConfigDto =
Expand Down Expand Up @@ -338,6 +339,8 @@ type FSACConfig =
{
/// <summary>The <see cref='F:Microsoft.Extensions.Caching.Memory.MemoryCacheOptions.SizeLimit '/> for typecheck cache. </summary>
CachedTypeCheckCount: int64
/// <summary>Whether to use parallel reference resolution in the compiler. See <see href="https://fsharp.github.io/fsharp-compiler-docs/reference/fsharp-compiler-codeanalysis-fsharpchecker.html#Create">the docs</see> for details.</summary>
ParallelReferenceResolution: bool
}

static member Default: FSACConfig
Expand Down
47 changes: 45 additions & 2 deletions src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ type AdaptiveFSharpLspServer

let checker =
config
|> AVal.map (fun c -> c.EnableAnalyzers, c.Fsac.CachedTypeCheckCount)
|> AVal.map (fun c -> c.EnableAnalyzers, c.Fsac.CachedTypeCheckCount, c.Fsac.ParallelReferenceResolution)
|> AVal.map (FSharpCompilerServiceChecker)

/// The reality is a file can be in multiple projects
Expand Down Expand Up @@ -1642,6 +1642,49 @@ type AdaptiveFSharpLspServer
text
tyRes

let symbolUseWorkspace2
(includeDeclarations: bool)
(includeBackticks: bool)
(errorOnFailureToFixRange: bool)
pos
lineStr
text
tyRes
=
let findReferencesForSymbolInFile (file: string<LocalPath>, project, symbol) =
async {
let checker = checker |> AVal.force

if File.Exists(UMX.untag file) then
// `FSharpChecker.FindBackgroundReferencesInFile` only works with existing files
return! checker.FindReferencesForSymbolInFile(UMX.untag file, project, symbol)
else
// untitled script files
match! forceGetTypeCheckResultsStale file with
| Error _ -> return Seq.empty
| Ok tyRes ->
let! ct = Async.CancellationToken
let usages = tyRes.GetCheckResults.GetUsesOfSymbolInFile(symbol, ct)
return usages |> Seq.map (fun u -> u.Range)
}

let tryGetProjectOptionsForFsproj (file: string<LocalPath>) =
forceGetFSharpProjectOptions file |> Async.map Option.ofResult

Commands.symbolUseWorkspace
getDeclarationLocation
findReferencesForSymbolInFile
forceFindSourceText
tryGetProjectOptionsForFsproj
(getAllFSharpProjectOptions >> Async.map Array.toSeq)
includeDeclarations
includeBackticks
errorOnFailureToFixRange
pos
lineStr
text
tyRes

let codefixes =

let tryGetParseResultsForFile filePath pos =
Expand Down Expand Up @@ -1779,7 +1822,7 @@ type AdaptiveFSharpLspServer
RemoveRedundantAttributeSuffix.fix tryGetParseResultsForFile
Run.ifEnabled
(fun _ -> config.AddPrivateAccessModifier)
(AddPrivateAccessModifier.fix tryGetParseResultsForFile symbolUseWorkspace)
(AddPrivateAccessModifier.fix tryGetParseResultsForFile symbolUseWorkspace2)
UseTripleQuotedInterpolation.fix tryGetParseResultsForFile getRangeText
RenameParamToMatchSignature.fix tryGetParseResultsForFile
RemovePatternArgument.fix tryGetParseResultsForFile
Expand Down
8 changes: 6 additions & 2 deletions src/FsAutoComplete/LspServers/FsAutoComplete.Lsp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type FSharpLspServer(state: State, lspClient: FSharpLspClient, sourceTextFactory
let mutable rootPath: string option = None

let mutable commands =
new Commands(FSharpCompilerServiceChecker(false, 200L), state, false, rootPath, sourceTextFactory)
new Commands(FSharpCompilerServiceChecker(false, 200L, false), state, false, rootPath, sourceTextFactory)

let mutable commandDisposables = ResizeArray()
let mutable clientCapabilities: ClientCapabilities option = None
Expand Down Expand Up @@ -486,7 +486,11 @@ type FSharpLspServer(state: State, lspClient: FSharpLspClient, sourceTextFactory

let newCommands =
new Commands(
FSharpCompilerServiceChecker(hasAnalyzersNow, config.Fsac.CachedTypeCheckCount),
FSharpCompilerServiceChecker(
hasAnalyzersNow,
config.Fsac.CachedTypeCheckCount,
config.Fsac.ParallelReferenceResolution
),
state,
hasAnalyzersNow,
rootPath,
Expand Down
Loading

0 comments on commit 5be7315

Please sign in to comment.