Skip to content

Commit 4c79b01

Browse files
committed
Initial msbuild properties support
1 parent 02dd353 commit 4c79b01

File tree

7 files changed

+62
-14
lines changed

7 files changed

+62
-14
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,9 @@ type NotificationsDto =
604604
{ Trace: bool option
605605
TraceNamespaces: string array option }
606606

607+
type BuildOptionsDto =
608+
{ MsBuildProperties: string array option }
609+
607610
type DebugDto =
608611
{ DontCheckRelatedFiles: bool option
609612
CheckFileDebouncerTimeout: int option
@@ -648,6 +651,7 @@ type FSharpConfigDto =
648651
PipelineHints: InlineValueDto option
649652
InlayHints: InlayHintDto option
650653
Notifications: NotificationsDto option
654+
BuildOptions: BuildOptionsDto option
651655
Debug: DebugDto option }
652656

653657
type FSharpConfigRequest = { FSharp: FSharpConfigDto }
@@ -695,6 +699,18 @@ type NotificationsConfig =
695699
{ Trace = defaultArg dto.Trace this.Trace
696700
TraceNamespaces = defaultArg dto.TraceNamespaces this.TraceNamespaces }
697701

702+
type BuildOptions =
703+
{ MsBuildProperties: string array }
704+
705+
static member Default = { MsBuildProperties = [||] }
706+
707+
static member FromDto(dto: BuildOptionsDto) : BuildOptions =
708+
{ MsBuildProperties = defaultArg dto.MsBuildProperties BuildOptions.Default.MsBuildProperties }
709+
710+
711+
member this.AddDto(dto: BuildOptionsDto) : BuildOptions =
712+
{ MsBuildProperties = defaultArg dto.MsBuildProperties this.MsBuildProperties }
713+
698714
type DebugConfig =
699715
{ DontCheckRelatedFiles: bool
700716
CheckFileDebouncerTimeout: int
@@ -745,6 +761,7 @@ type FSharpConfig =
745761
InlayHints: InlayHintsConfig
746762
InlineValues: InlineValuesConfig
747763
Notifications: NotificationsConfig
764+
BuildOptions: BuildOptions
748765
Debug: DebugConfig }
749766

750767
static member Default: FSharpConfig =
@@ -785,6 +802,7 @@ type FSharpConfig =
785802
InlayHints = InlayHintsConfig.Default
786803
InlineValues = InlineValuesConfig.Default
787804
Notifications = NotificationsConfig.Default
805+
BuildOptions = BuildOptions.Default
788806
Debug = DebugConfig.Default }
789807

790808
static member FromDto(dto: FSharpConfigDto) : FSharpConfig =
@@ -853,6 +871,10 @@ type FSharpConfig =
853871
dto.Notifications
854872
|> Option.map NotificationsConfig.FromDto
855873
|> Option.defaultValue NotificationsConfig.Default
874+
BuildOptions =
875+
dto.BuildOptions
876+
|> Option.map BuildOptions.FromDto
877+
|> Option.defaultValue BuildOptions.Default
856878
Debug =
857879
match dto.Debug with
858880
| None -> DebugConfig.Default
@@ -939,6 +961,10 @@ type FSharpConfig =
939961
dto.Notifications
940962
|> Option.map x.Notifications.AddDto
941963
|> Option.defaultValue NotificationsConfig.Default
964+
BuildOptions =
965+
dto.BuildOptions
966+
|> Option.map x.BuildOptions.AddDto
967+
|> Option.defaultValue BuildOptions.Default
942968
Debug =
943969
match dto.Debug with
944970
| None -> DebugConfig.Default

src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ type AdaptiveWorkspaceChosen =
176176
| Projs of aval<HashMap<string<LocalPath>, DateTime>>
177177
| NotChosen
178178

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

181181
let thisType = typeof<AdaptiveFSharpLspServer>
182182

@@ -630,8 +630,23 @@ type AdaptiveFSharpLspServer(workspaceLoader: IWorkspaceLoader, lspClient: FShar
630630

631631
file |> addAValLogging logMsg
632632

633-
let loader = cval<Ionide.ProjInfo.IWorkspaceLoader> workspaceLoader
633+
let loaderFactory = cval<Map<string, string> -> Ionide.ProjInfo.IWorkspaceLoader> workspaceLoader
634+
let loader =
635+
aval {
636+
let! loaderFactory = loaderFactory
637+
and! config = config
638+
639+
let props =
640+
config.BuildOptions.MsBuildProperties
641+
|> Array.choose(fun s ->
642+
match s.Split("=") |> Array.toList with
643+
| head::shoulders::_ -> Some(head,shoulders)
644+
| _ -> None
645+
)
646+
|> Map.ofArray
634647

648+
return loaderFactory props
649+
}
635650

636651

637652
let binlogConfig =

src/FsAutoComplete/LspServers/FsAutoComplete.Lsp.fs

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

29442944
let regularServer lspClient =
2945-
let state = State.Initial toolsPath stateStorageDir workspaceLoaderFactory
2945+
let state = State.Initial toolsPath stateStorageDir (fun toolsPath -> workspaceLoaderFactory toolsPath Map.empty)
29462946
let originalFs = FSharp.Compiler.IO.FileSystemAutoOpens.FileSystem
29472947
FSharp.Compiler.IO.FileSystemAutoOpens.FileSystem <- FsAutoComplete.FileSystem(originalFs, state.Files.TryFind)
29482948
new FSharpLspServer(state, lspClient) :> IFSharpLspServer

src/FsAutoComplete/Parser.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ module Parser =
9999

100100
let otelTracingOption =
101101
Option<bool>(
102-
"--otel-tracing-enabled",
102+
"--otel-exporter-enabled",
103103
"Enabled OpenTelemetry exporter. See https://opentelemetry.io/docs/reference/specification/protocol/exporter/ for environment variables to configure for the exporter."
104104
)
105105

@@ -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.HasOption 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
@@ -270,6 +270,7 @@ let defaultConfigDto: FSharpConfigDto =
270270
{ Enabled = Some true
271271
Prefix = Some "//" }
272272
Notifications = None
273+
BuildOptions = None
273274
Debug = None }
274275

275276
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

@@ -191,9 +193,12 @@ let main args =
191193
args
192194
|> Array.windowed 2
193195
|> Array.tryPick (function
194-
| [| "--loader"; "ionide" |] as args -> Some(args, [ "Ionide WorkspaceLoader", WorkspaceLoader.Create ])
196+
| [| "--loader"; "ionide" |] as args ->
197+
let (name, factory) = loaders |> Seq.find(fun (k,v) -> k = "Ionide WorkspaceLoader")
198+
Some(args, [ name, factory ])
195199
| [| "--loader"; "graph" |] as args ->
196-
Some(args, [ "MSBuild Project Graph WorkspaceLoader", WorkspaceLoaderViaProjectGraph.Create ])
200+
let (name, factory) = loaders |> Seq.find(fun (k,v) -> k = "MSBuild Project Graph WorkspaceLoader")
201+
Some(args, [ name, factory ])
197202
| _ -> None)
198203
|> Option.defaultValue ([||], loaders)
199204

0 commit comments

Comments
 (0)