Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to set Msbuild properties for design time #1065

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/FsAutoComplete.Core/Consts.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module ProjectLoader =
let ProduceReferenceAssembly = "ProduceReferenceAssembly"

let globalProperties =
[
// For tooling we don't want to use Reference Assemblies as this doesn't play well with type checking across projects
ProduceReferenceAssembly, "false" ]
Map.ofList
[
// For tooling we don't want to use Reference Assemblies as this doesn't play well with type checking across projects
ProduceReferenceAssembly, "false" ]
30 changes: 30 additions & 0 deletions src/FsAutoComplete/LspHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ type NotificationsDto =
{ Trace: bool option
TraceNamespaces: string array option }

type BuildOptionsDto =
{ MsBuildProperties: Dictionary<string, string> option }

type DebugDto =
{ DontCheckRelatedFiles: bool option
CheckFileDebouncerTimeout: int option
Expand Down Expand Up @@ -662,6 +665,7 @@ type FSharpConfigDto =
InlayHints: InlayHintDto option
Fsac: FSACDto option
Notifications: NotificationsDto option
BuildOptions: BuildOptionsDto option
Debug: DebugDto option }

type FSharpConfigRequest = { FSharp: FSharpConfigDto option }
Expand Down Expand Up @@ -726,6 +730,22 @@ type FSACConfig =
member this.AddDto(dto: FSACDto) =
{ CachedTypeCheckCount = defaultArg dto.CachedTypeCheckCount this.CachedTypeCheckCount }

type BuildOptions =
{ MsBuildProperties: Map<string, string> }

static member Default = { MsBuildProperties = Map.empty }

static member FromDto(dto: BuildOptionsDto) : BuildOptions =
let props = dto.MsBuildProperties |> Option.map (Seq.map (|KeyValue|) >> Map.ofSeq)

{ MsBuildProperties = defaultArg props BuildOptions.Default.MsBuildProperties }


member this.AddDto(dto: BuildOptionsDto) : BuildOptions =
let props = dto.MsBuildProperties |> Option.map (Seq.map (|KeyValue|) >> Map.ofSeq)

{ MsBuildProperties = defaultArg props this.MsBuildProperties }

type DebugConfig =
{ DontCheckRelatedFiles: bool
CheckFileDebouncerTimeout: int
Expand Down Expand Up @@ -778,6 +798,7 @@ type FSharpConfig =
InlineValues: InlineValuesConfig
Notifications: NotificationsConfig
Fsac: FSACConfig
BuildOptions: BuildOptions
Debug: DebugConfig }

static member Default: FSharpConfig =
Expand Down Expand Up @@ -820,6 +841,7 @@ type FSharpConfig =
InlineValues = InlineValuesConfig.Default
Notifications = NotificationsConfig.Default
Fsac = FSACConfig.Default
BuildOptions = BuildOptions.Default
Debug = DebugConfig.Default }

static member FromDto(dto: FSharpConfigDto) : FSharpConfig =
Expand Down Expand Up @@ -893,6 +915,10 @@ type FSharpConfig =
dto.Fsac
|> Option.map FSACConfig.FromDto
|> Option.defaultValue FSACConfig.Default
BuildOptions =
dto.BuildOptions
|> Option.map BuildOptions.FromDto
|> Option.defaultValue BuildOptions.Default
Debug =
match dto.Debug with
| None -> DebugConfig.Default
Expand Down Expand Up @@ -981,6 +1007,10 @@ type FSharpConfig =
|> Option.map x.Notifications.AddDto
|> Option.defaultValue NotificationsConfig.Default
Fsac = dto.Fsac |> Option.map x.Fsac.AddDto |> Option.defaultValue FSACConfig.Default
BuildOptions =
dto.BuildOptions
|> Option.map x.BuildOptions.AddDto
|> Option.defaultValue BuildOptions.Default
Debug =
match dto.Debug with
| None -> DebugConfig.Default
Expand Down
12 changes: 10 additions & 2 deletions src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type AdaptiveWorkspaceChosen =
| Projs of amap<string<LocalPath>, DateTime>
| NotChosen

type AdaptiveFSharpLspServer(workspaceLoader: IWorkspaceLoader, lspClient: FSharpLspClient) =
type AdaptiveFSharpLspServer(workspaceLoader: Map<string, string> -> IWorkspaceLoader, lspClient: FSharpLspClient) =

let thisType = typeof<AdaptiveFSharpLspServer>

Expand Down Expand Up @@ -509,8 +509,16 @@ type AdaptiveFSharpLspServer(workspaceLoader: IWorkspaceLoader, lspClient: FShar

file |> addAValLogging logMsg

let loader = cval<Ionide.ProjInfo.IWorkspaceLoader> workspaceLoader
let loaderFactory =
cval<Map<string, string> -> Ionide.ProjInfo.IWorkspaceLoader> workspaceLoader

let loader =
aval {
let! loaderFactory = loaderFactory
and! config = config

return loaderFactory config.BuildOptions.MsBuildProperties
}


let binlogConfig =
Expand Down
4 changes: 3 additions & 1 deletion src/FsAutoComplete/LspServers/FsAutoComplete.Lsp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2953,7 +2953,9 @@ module FSharpLspServer =
|> Map.add "fsproj/removeFile" (serverRequestHandling (fun s p -> s.FsProjRemoveFile(p)))

let regularServer lspClient =
let state = State.Initial toolsPath stateStorageDir workspaceLoaderFactory
let state =
State.Initial toolsPath stateStorageDir (fun toolsPath -> workspaceLoaderFactory toolsPath Map.empty)

let originalFs = FSharp.Compiler.IO.FileSystemAutoOpens.FileSystem
FSharp.Compiler.IO.FileSystemAutoOpens.FileSystem <- FsAutoComplete.FileSystem(originalFs, state.Files.TryFind)
new FSharpLspServer(state, lspClient) :> IFSharpLspServer
Expand Down
8 changes: 5 additions & 3 deletions src/FsAutoComplete/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ module Parser =
rootCommand.SetHandler(
Func<_, _, _, Task>(fun projectGraphEnabled stateDirectory adaptiveLspEnabled ->
let workspaceLoaderFactory =
fun toolsPath ->
fun toolsPath props ->
let props = Map.merge ProjectLoader.globalProperties props |> Map.toList

if projectGraphEnabled then
Ionide.ProjInfo.WorkspaceLoaderViaProjectGraph.Create(toolsPath, ProjectLoader.globalProperties)
Ionide.ProjInfo.WorkspaceLoaderViaProjectGraph.Create(toolsPath, props)
else
Ionide.ProjInfo.WorkspaceLoader.Create(toolsPath, ProjectLoader.globalProperties)
Ionide.ProjInfo.WorkspaceLoader.Create(toolsPath, props)

let dotnetPath =
if
Expand Down
1 change: 1 addition & 0 deletions test/FsAutoComplete.Tests.Lsp/Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ let defaultConfigDto: FSharpConfigDto =
Prefix = Some "//" }
Notifications = None
Fsac = None
BuildOptions = None
Debug = None }

let clientCaps: ClientCapabilities =
Expand Down
11 changes: 8 additions & 3 deletions test/FsAutoComplete.Tests.Lsp/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ Environment.SetEnvironmentVariable("FSAC_WORKSPACELOAD_DELAY", "250")

let loaders =
[
"Ionide WorkspaceLoader", (fun toolpath -> WorkspaceLoader.Create(toolpath, FsAutoComplete.Core.ProjectLoader.globalProperties))
"Ionide WorkspaceLoader", (fun toolpath props ->
let props = FsAutoComplete.Utils.Map.merge FsAutoComplete.Core.ProjectLoader.globalProperties props |> Map.toList
WorkspaceLoader.Create(toolpath, props))
// "MSBuild Project Graph WorkspaceLoader", (fun toolpath -> WorkspaceLoaderViaProjectGraph.Create(toolpath, FsAutoComplete.Core.ProjectLoader.globalProperties))
]

Expand Down Expand Up @@ -195,9 +197,12 @@ let main args =
args
|> Array.windowed 2
|> Array.tryPick (function
| [| "--loader"; "ionide" |] as args -> Some(args, [ "Ionide WorkspaceLoader", WorkspaceLoader.Create ])
| [| "--loader"; "ionide" |] as args ->
let (name, factory) = loaders |> Seq.find(fun (k,v) -> k = "Ionide WorkspaceLoader")
Some(args, [ name, factory ])
| [| "--loader"; "graph" |] as args ->
Some(args, [ "MSBuild Project Graph WorkspaceLoader", WorkspaceLoaderViaProjectGraph.Create ])
let (name, factory) = loaders |> Seq.find(fun (k,v) -> k = "MSBuild Project Graph WorkspaceLoader")
Some(args, [ name, factory ])
| _ -> None)
|> Option.defaultValue ([||], loaders)

Expand Down