Skip to content

Commit 11fcf6e

Browse files
committed
Initial msbuild properties support
1 parent 3b1a8cb commit 11fcf6e

File tree

7 files changed

+60
-13
lines changed

7 files changed

+60
-13
lines changed

src/FsAutoComplete.Core/Consts.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module ProjectLoader =
55
let ProduceReferenceAssembly = "ProduceReferenceAssembly"
66

77
let globalProperties =
8-
[
9-
// For tooling we don't want to use Reference Assemblies as this doesn't play well with type checking across projects
10-
ProduceReferenceAssembly, "false" ]
8+
Map.ofList
9+
[
10+
// For tooling we don't want to use Reference Assemblies as this doesn't play well with type checking across projects
11+
ProduceReferenceAssembly, "false" ]

src/FsAutoComplete/LspHelpers.fs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,9 @@ type NotificationsDto =
609609
{ Trace: bool option
610610
TraceNamespaces: string array option }
611611

612+
type BuildOptionsDto =
613+
{ MsBuildProperties: string array option }
614+
612615
type DebugDto =
613616
{ DontCheckRelatedFiles: bool option
614617
CheckFileDebouncerTimeout: int option
@@ -662,6 +665,7 @@ type FSharpConfigDto =
662665
InlayHints: InlayHintDto option
663666
Fsac: FSACDto option
664667
Notifications: NotificationsDto option
668+
BuildOptions: BuildOptionsDto option
665669
Debug: DebugDto option }
666670

667671
type FSharpConfigRequest = { FSharp: FSharpConfigDto option }
@@ -725,6 +729,17 @@ type FSACConfig =
725729

726730
member this.AddDto(dto: FSACDto) =
727731
{ CachedTypeCheckCount = defaultArg dto.CachedTypeCheckCount this.CachedTypeCheckCount }
732+
type BuildOptions =
733+
{ MsBuildProperties: string array }
734+
735+
static member Default = { MsBuildProperties = [||] }
736+
737+
static member FromDto(dto: BuildOptionsDto) : BuildOptions =
738+
{ MsBuildProperties = defaultArg dto.MsBuildProperties BuildOptions.Default.MsBuildProperties }
739+
740+
741+
member this.AddDto(dto: BuildOptionsDto) : BuildOptions =
742+
{ MsBuildProperties = defaultArg dto.MsBuildProperties this.MsBuildProperties }
728743

729744
type DebugConfig =
730745
{ DontCheckRelatedFiles: bool
@@ -778,6 +793,7 @@ type FSharpConfig =
778793
InlineValues: InlineValuesConfig
779794
Notifications: NotificationsConfig
780795
Fsac: FSACConfig
796+
BuildOptions: BuildOptions
781797
Debug: DebugConfig }
782798

783799
static member Default: FSharpConfig =
@@ -820,6 +836,7 @@ type FSharpConfig =
820836
InlineValues = InlineValuesConfig.Default
821837
Notifications = NotificationsConfig.Default
822838
Fsac = FSACConfig.Default
839+
BuildOptions = BuildOptions.Default
823840
Debug = DebugConfig.Default }
824841

825842
static member FromDto(dto: FSharpConfigDto) : FSharpConfig =
@@ -893,6 +910,10 @@ type FSharpConfig =
893910
dto.Fsac
894911
|> Option.map FSACConfig.FromDto
895912
|> Option.defaultValue FSACConfig.Default
913+
BuildOptions =
914+
dto.BuildOptions
915+
|> Option.map BuildOptions.FromDto
916+
|> Option.defaultValue BuildOptions.Default
896917
Debug =
897918
match dto.Debug with
898919
| None -> DebugConfig.Default
@@ -981,6 +1002,10 @@ type FSharpConfig =
9811002
|> Option.map x.Notifications.AddDto
9821003
|> Option.defaultValue NotificationsConfig.Default
9831004
Fsac = dto.Fsac |> Option.map x.Fsac.AddDto |> Option.defaultValue FSACConfig.Default
1005+
BuildOptions =
1006+
dto.BuildOptions
1007+
|> Option.map x.BuildOptions.AddDto
1008+
|> Option.defaultValue BuildOptions.Default
9841009
Debug =
9851010
match dto.Debug with
9861011
| None -> DebugConfig.Default

src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type AdaptiveWorkspaceChosen =
5454
| Projs of amap<string<LocalPath>, DateTime>
5555
| NotChosen
5656

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

5959
let thisType = typeof<AdaptiveFSharpLspServer>
6060

@@ -509,8 +509,23 @@ type AdaptiveFSharpLspServer(workspaceLoader: IWorkspaceLoader, lspClient: FShar
509509

510510
file |> addAValLogging logMsg
511511

512-
let loader = cval<Ionide.ProjInfo.IWorkspaceLoader> workspaceLoader
512+
let loaderFactory = cval<Map<string, string> -> Ionide.ProjInfo.IWorkspaceLoader> workspaceLoader
513+
let loader =
514+
aval {
515+
let! loaderFactory = loaderFactory
516+
and! config = config
517+
518+
let props =
519+
config.BuildOptions.MsBuildProperties
520+
|> Array.choose(fun s ->
521+
match s.Split("=") |> Array.toList with
522+
| head::shoulders::_ -> Some(head,shoulders)
523+
| _ -> None
524+
)
525+
|> Map.ofArray
513526

527+
return loaderFactory props
528+
}
514529

515530

516531
let binlogConfig =

src/FsAutoComplete/LspServers/FsAutoComplete.Lsp.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2953,7 +2953,7 @@ module FSharpLspServer =
29532953
|> Map.add "fsproj/removeFile" (serverRequestHandling (fun s p -> s.FsProjRemoveFile(p)))
29542954

29552955
let regularServer lspClient =
2956-
let state = State.Initial toolsPath stateStorageDir workspaceLoaderFactory
2956+
let state = State.Initial toolsPath stateStorageDir (fun toolsPath -> workspaceLoaderFactory toolsPath Map.empty)
29572957
let originalFs = FSharp.Compiler.IO.FileSystemAutoOpens.FileSystem
29582958
FSharp.Compiler.IO.FileSystemAutoOpens.FileSystem <- FsAutoComplete.FileSystem(originalFs, state.Files.TryFind)
29592959
new FSharpLspServer(state, lspClient) :> IFSharpLspServer

src/FsAutoComplete/Parser.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,12 @@ module Parser =
130130
rootCommand.SetHandler(
131131
Func<_, _, _, Task>(fun projectGraphEnabled stateDirectory adaptiveLspEnabled ->
132132
let workspaceLoaderFactory =
133-
fun toolsPath ->
133+
fun toolsPath props ->
134+
let props = Map.merge ProjectLoader.globalProperties props |> Map.toList
134135
if projectGraphEnabled then
135-
Ionide.ProjInfo.WorkspaceLoaderViaProjectGraph.Create(toolsPath, ProjectLoader.globalProperties)
136+
Ionide.ProjInfo.WorkspaceLoaderViaProjectGraph.Create(toolsPath, props)
136137
else
137-
Ionide.ProjInfo.WorkspaceLoader.Create(toolsPath, ProjectLoader.globalProperties)
138+
Ionide.ProjInfo.WorkspaceLoader.Create(toolsPath, props)
138139

139140
let dotnetPath =
140141
if
@@ -191,7 +192,6 @@ module Parser =
191192
if ctx.ParseResult.GetValueForOption otelTracingOption then
192193
let serviceName = FsAutoComplete.Utils.Tracing.serviceName
193194
let version = FsAutoComplete.Utils.Version.info().Version
194-
195195
tracerProvider <-
196196
Sdk
197197
.CreateTracerProviderBuilder()

test/FsAutoComplete.Tests.Lsp/Helpers.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ let defaultConfigDto: FSharpConfigDto =
272272
Prefix = Some "//" }
273273
Notifications = None
274274
Fsac = None
275+
BuildOptions = None
275276
Debug = None }
276277

277278
let clientCaps: ClientCapabilities =

test/FsAutoComplete.Tests.Lsp/Program.fs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ Environment.SetEnvironmentVariable("FSAC_WORKSPACELOAD_DELAY", "250")
3232

3333
let loaders =
3434
[
35-
"Ionide WorkspaceLoader", (fun toolpath -> WorkspaceLoader.Create(toolpath, FsAutoComplete.Core.ProjectLoader.globalProperties))
35+
"Ionide WorkspaceLoader", (fun toolpath props ->
36+
let props = FsAutoComplete.Utils.Map.merge FsAutoComplete.Core.ProjectLoader.globalProperties props |> Map.toList
37+
WorkspaceLoader.Create(toolpath, props))
3638
// "MSBuild Project Graph WorkspaceLoader", (fun toolpath -> WorkspaceLoaderViaProjectGraph.Create(toolpath, FsAutoComplete.Core.ProjectLoader.globalProperties))
3739
]
3840

@@ -195,9 +197,12 @@ let main args =
195197
args
196198
|> Array.windowed 2
197199
|> Array.tryPick (function
198-
| [| "--loader"; "ionide" |] as args -> Some(args, [ "Ionide WorkspaceLoader", WorkspaceLoader.Create ])
200+
| [| "--loader"; "ionide" |] as args ->
201+
let (name, factory) = loaders |> Seq.find(fun (k,v) -> k = "Ionide WorkspaceLoader")
202+
Some(args, [ name, factory ])
199203
| [| "--loader"; "graph" |] as args ->
200-
Some(args, [ "MSBuild Project Graph WorkspaceLoader", WorkspaceLoaderViaProjectGraph.Create ])
204+
let (name, factory) = loaders |> Seq.find(fun (k,v) -> k = "MSBuild Project Graph WorkspaceLoader")
205+
Some(args, [ name, factory ])
201206
| _ -> None)
202207
|> Option.defaultValue ([||], loaders)
203208

0 commit comments

Comments
 (0)