Skip to content

Commit

Permalink
Add change tracking for projects (#659)
Browse files Browse the repository at this point in the history
This adds proper change tracking for `fsproj` files and `asset` files. Up to this point, we were depending on Ionide to track those changes and set `load` request when necessary, which was problematic for different LSP clients.

There are additional two things that we probably should move to FSAC that are currently done on Ionide side, but I'll move them in separate PRs:
* watch for changes in `sln` file
* run `dotnet restore` if project loading returns NotResotred status.
  • Loading branch information
Krzysztof-Cieslak committed Nov 6, 2020
1 parent 2c0cb16 commit c4e11d7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/FsAutoComplete.Core/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -838,17 +838,17 @@ type Commands<'analyzer> (serialize : Serializer, backgroundServiceEnabled) =
return CoreResponse.Res d
}

member x.WorkspaceLoad onChange (files: string list) (disableInMemoryProjectReferences: bool) tfmForScripts (generateBinlog: bool) = async {
member x.WorkspaceLoad (files: string list) (disableInMemoryProjectReferences: bool) tfmForScripts (generateBinlog: bool) = async {
commandsLogger.info (Log.setMessage "Workspace loading started '{files}'" >> Log.addContextDestructured "files" files)
checker.DisableInMemoryProjectReferences <- disableInMemoryProjectReferences
let! res = state.ProjectController.LoadWorkspace onChange files tfmForScripts onProjectLoaded generateBinlog
let! res = state.ProjectController.LoadWorkspace files tfmForScripts onProjectLoaded generateBinlog
commandsLogger.info (Log.setMessage "Workspace loading finished ")
return CoreResponse.Res res
}

member x.Project onChange projectFileName tfmForScripts (generateBinlog: bool) = async {
member x.Project projectFileName tfmForScripts (generateBinlog: bool) = async {
commandsLogger.info (Log.setMessage "Project loading '{file}'" >> Log.addContextDestructured "file" projectFileName)
let! res = state.ProjectController.LoadProject onChange projectFileName tfmForScripts onProjectLoaded generateBinlog
let! res = state.ProjectController.LoadProject projectFileName tfmForScripts onProjectLoaded generateBinlog
return CoreResponse.Res res
}

Expand Down
8 changes: 4 additions & 4 deletions src/FsAutoComplete/FsAutoComplete.Lsp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -532,15 +532,15 @@ type FsharpLspServer(commands: Commands, lspClient: FSharpLspClient) =
match peeks with
| [] -> ()
| [CommandResponse.WorkspacePeekFound.Directory projs] ->
commands.WorkspaceLoad ignore projs.Fsprojs false config.ScriptTFM config.GenerateBinlog
commands.WorkspaceLoad projs.Fsprojs false config.ScriptTFM config.GenerateBinlog
|> Async.Ignore
|> Async.Start
| CommandResponse.WorkspacePeekFound.Solution sln::_ ->
let projs =
sln.Items
|> List.collect Workspace.foldFsproj
|> List.map fst
commands.WorkspaceLoad ignore projs false config.ScriptTFM config.GenerateBinlog
commands.WorkspaceLoad projs false config.ScriptTFM config.GenerateBinlog
|> Async.Ignore
|> Async.Start
| _ ->
Expand Down Expand Up @@ -1805,7 +1805,7 @@ type FsharpLspServer(commands: Commands, lspClient: FSharpLspClient) =
logger.info (Log.setMessage "FSharpWorkspaceLoad Request: {parms}" >> Log.addContextDestructured "parms" p )

let fns = p.TextDocuments |> Array.map (fun fn -> fn.GetFilePath() ) |> Array.toList
let! res = commands.WorkspaceLoad ignore fns config.DisableInMemoryProjectReferences config.ScriptTFM config.GenerateBinlog
let! res = commands.WorkspaceLoad fns config.DisableInMemoryProjectReferences config.ScriptTFM config.GenerateBinlog
let res =
match res with
| CoreResponse.InfoRes msg | CoreResponse.ErrorRes msg ->
Expand Down Expand Up @@ -1836,7 +1836,7 @@ type FsharpLspServer(commands: Commands, lspClient: FSharpLspClient) =
logger.info (Log.setMessage "FSharpProject Request: {parms}" >> Log.addContextDestructured "parms" p )

let fn = p.Project.GetFilePath()
let! res = commands.Project ignore fn config.ScriptTFM config.GenerateBinlog
let! res = commands.Project fn config.ScriptTFM config.GenerateBinlog
let res =
match res with
| CoreResponse.InfoRes msg | CoreResponse.ErrorRes msg ->
Expand Down
15 changes: 10 additions & 5 deletions src/ProjectSystem/ProjectSystem.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type ProjectController(checker : FSharpChecker) =

member private x.LoaderLoop = MailboxProcessor.Start(fun agent ->
let rec loop () = async {
let! ((oc, fn, tfm, ol, gb), reply : AsyncReplyChannel<_>) = agent.Receive()
let! ((fn, tfm, ol, gb), reply : AsyncReplyChannel<_>) = agent.Receive()
let mutable wasInvoked = false
let! x =
Async.FromContinuations( fun (succ, err, cancl) ->
Expand All @@ -85,7 +85,7 @@ type ProjectController(checker : FSharpChecker) =
else
wasInvoked <- true
succ ()
x.LoadWorkspace oc [fn] tfm opl gb |> Async.Ignore |> Async.Start
x.LoadWorkspace [fn] tfm opl gb |> Async.Ignore |> Async.Start
)

reply.Reply true
Expand Down Expand Up @@ -127,14 +127,19 @@ type ProjectController(checker : FSharpChecker) =
projects
|> Seq.map (|KeyValue|)

member x.LoadProject onChange projectFileName (tfmForScripts: FSIRefs.TFM) onProjectLoaded (generateBinlog: bool) =
x.LoaderLoop.PostAndAsyncReply(fun acr -> (onChange, projectFileName, tfmForScripts, onProjectLoaded, generateBinlog ), acr )
member x.LoadProject projectFileName (tfmForScripts: FSIRefs.TFM) onProjectLoaded (generateBinlog: bool) =
x.LoaderLoop.PostAndAsyncReply(fun acr -> (projectFileName, tfmForScripts, onProjectLoaded, generateBinlog ), acr )


member __.LoadWorkspace onChange (files: string list) (tfmForScripts: FSIRefs.TFM) onProjectLoaded (generateBinlog: bool) = async {
member x.LoadWorkspace (files: string list) (tfmForScripts: FSIRefs.TFM) onProjectLoaded (generateBinlog: bool) = async {
//TODO check full path
let projectFileNames = files |> List.map Path.GetFullPath

let onChange fn =
x.LoadProject fn tfmForScripts onProjectLoaded generateBinlog
|> Async.Ignore
|> Async.Start

let prjs =
projectFileNames
|> List.map (fun projectFileName -> projectFileName, new Project(projectFileName, onChange))
Expand Down

0 comments on commit c4e11d7

Please sign in to comment.