Skip to content

Improve fake script support - #402

Merged
enricosada merged 7 commits into
ionide:masterfrom
matthid:improve_fake_script_support
Jun 13, 2019
Merged

enricosada merged 7 commits into
ionide:masterfrom
matthid:improve_fake_script_support

Conversation

@matthid

@matthid matthid commented Jun 10, 2019 •

Copy link
Copy Markdown
Contributor

playing around with the code. Goal is:

  • Automatically restore and load references via Fake.Runtime when opening a script
  • Automatically suggest updating dependencies when header changes

TODO:

  • Check why colorization is not working in the Extension Development Host
  • Update Fake.Runtime and remove reflection based code
  • (optional) Progress indicator when restoring packages

I started with the code in https://github.com/ionide/ionide-vscode-fsharp, now there are conflicts. Do I need to update the ionide-vscode-fsharp reference?

Note: for this small change it is already working way better than expected:

@matthid

matthid commented Jun 10, 2019

Copy link
Copy Markdown
Contributor Author

I need some support on these points:

  • Is it ok to reference Fake.Runtime here? If not: Any suggestions on how to implement this instead?

  • How to test Colorization?

  • Automatically suggest updating dependencies when header changes

    What would be the best and most efficient way to implement this?
    For example is it good to do this on every keystroke? Are there other strategies?
    Basically I want to detect if something either changes in the #r "paket" line or the associated paket.dependencies or paket.lock file and then change the FSharpProjectOptions accordingly (is this even possible today?)

matthid added a commit to fsprojects/FAKE that referenced this pull request Jun 10, 2019
…o improve_fake_script_support

 Conflicts:
	paket.lock
	src/FsAutoComplete.Core/Commands.fs
	src/FsAutoComplete.Core/CompilerServiceInterface.fs
	src/FsAutoComplete.Core/SimplifyNameAnalyzer.fs
@matthid

matthid commented Jun 10, 2019

Copy link
Copy Markdown
Contributor Author

Is it ok to reference Fake.Runtime here?

As I'm already running into issues after merging latest master I guess we should not underestimate this...
On the other hand, if we run another REST based service in order to work around this we loose performance because now FSharp.Compiler.Service needs to duplicate all the work...

@matthid

matthid commented Jun 10, 2019

Copy link
Copy Markdown
Contributor Author

Maybe the following could work for us:
We leave it as-is and I give the ionide contributors access to the fake release pipeline. Usually all that needs to be done is paket update, updating the release notes and sending a PR to release/next. After that you could just release by clicking the "Release to Production" button in Azure DevOps.

This would be only needed when there are (relevant) breaking changes in FSharp.Compiler.Service

If that process turns out to be too slow (Would say at least half a day until all builds/checks have run and the PR is Reviewed/merged). We could add a manual release path for https://www.nuget.org/packages/Fake.Runtime/ and https://www.nuget.org/packages/Fake.Core.Context/ (ie just dotnet pack and upload to NuGet). Which would be acceptable for -alpha packages.

@matthid matthid left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some general comments regarding the changes in this PR. Let me know if I should send some of them in a separate PR.

symbolUse, partialName.QualifyingIdents, plidStartCol, partialName.PartialIdent)
if symbolUse.RangeAlternate.EndLine <> symbolUse.RangeAlternate.StartLine then
// Problem: EndColumn > lineStr.Length -> logic needs to account for multiple lines..
symbolUse, [], 0, ""

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a logic flaw here (something changed with the merge as there was a conflict, but I think this is still true)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I understand why this needs to be changed. How can symbol usage be longer than one line? Can you post some sample code for that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code in question was this

    let depsFile = File.ReadAllText (gitDirectory </> "paket.dependencies")
    let replacedFile =
        depsFile
            .Replace("// FAKE_MYGET_FEED (don't edit this line)", "source https://www.myget.org/F/fake-vsts/api/v3/index.json")
            .Replace("prerelease // FAKE_VERSION (don't edit this line)", nugetVersion)
    File.WriteAllText(gitDirectory </> "paket.dependencies", replacedFile)

And I think Replace was marked the usage then is from depsFile to the next line until ( which is longer than the last line

Fake.Runtime.Trace.VerboseLevel.Verbose [] file [] true false
let prepared = Fake.Runtime.FakeRuntime.prepareFakeScript config
let isFakeScript = prepared.DependencyType <> Fake.Runtime.FakeRuntime.PreparedDependencyType.DefaultDependencies
if not isFakeScript then return projOptions

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until this isFakeScript check it should be pretty fast. prepareFakeScript basically does tokenize the script, which I feel is acceptable.
in the fake branch there is all the logic for downloading NuGet packages and resolving the proper arguments...

Comment thread src/FsAutoComplete.Core/Commands.fs Resolved
@matthid

matthid commented Jun 10, 2019

Copy link
Copy Markdown
Contributor Author
Scenario Before After
Open before running FAKE image See below (after some time)
After running Fake image image

@matthid matthid changed the title [WIP] Improve fake script support Improve fake script support Jun 10, 2019
@Krzysztof-Cieslak

Copy link
Copy Markdown
Member

I'll take a look at that tomorrow.

Do I need to update the ionide-vscode-fsharp reference?

The easiest way to test it should be using fsacUrl setting on current ionide version... however due to huge changes in FSAC recently I'm not sure if this would still work at the moment.

If you can build Ionide locally (i know it's bit problematic) you can try using ionide-vscode-fsharp 4.0 branch and updating reference to FSAC in paket.dependencies

@Krzysztof-Cieslak

Krzysztof-Cieslak commented Jun 11, 2019 •

Copy link
Copy Markdown
Member

OK, in general I like that.

My only worry is already mentioned fact that Fake.Runtime depends on FCS - we already have problems with our dependencies that also depends on FCS such as Linter and Analyzers.SDK - we need to be sure that we update everything or things breaks ;-) .
Because FAKE is really important part of the ecosystem, I'm OK with this, and I can accept this drawback just for sake of good UX with FAKE - we really need that. We usually try to help our dependencies with new FCS versions by sending appropriate PRs, I guess we can do just that for FAKE. If you think giving someone release rights will help, I'm sure @enricosada or @baronfel will be happy to help ;-)

Check why colorization is not working in the Extension Development Host

I'm not sure, it just works for me, have you run build.cmd Build in Ionide repo? (yes, this Build argument is important, it's not default option ;-) )

For example is it good to do this on every keystroke? Are there other strategies?

We update our internal state of the files on every keystroke. For something like detection of Paket header changes I guess we should use the same strategy as for typechecking - we use debouncer, and we start typechecking after user stopped writing for 500ms (exact timing can be different for this feature) - https://github.com/fsharp/FsAutoComplete/blob/master/src/FsAutoComplete/FsAutoComplete.Lsp.fs#L84

As for detecting changes in paket.dependencies and paket.lock - we can probably set up watcher on the client side https://github.com/ionide/ionide-vscode-fsharp/blob/4.0/src/Core/LanguageService.fs#L382 and use LSP WorkspaceDidChangeWatchedFiles endpoint - https://github.com/fsharp/FsAutoComplete/blob/master/src/FsAutoComplete/FsAutoComplete.Lsp.fs#L1278

@matthid

matthid commented Jun 11, 2019

Copy link
Copy Markdown
Contributor Author

we already have problems with our dependencies that also depends on FCS such as Linter and Analyzers.SDK - we need to be sure that we update everything or things breaks ;-)

Tell me about it... I'm maintaining Fsharp.formatting and FAKE both having fcs dependency and one running within the other ;)...

yes, this Build argument is important, it's not default option ;-)

Oh thanks, I'll try that

We update our internal state of the files on every keystroke

Thanks for the pointers I'll try to take a look.

What is your stand of PR size. Smaller features like it is now or complete UX story, or is it on me?

Note that I noticed another advantage of this PR. You no longer need the #load intellisense line. It might make sense for other IDEs but in fsac based stuff it will work with the header only

@Krzysztof-Cieslak

Copy link
Copy Markdown
Member

What is your stand of PR size. Smaller features like it is now or complete UX story, or is it on me?

I'm fine with either, but you need to remember that I update FSAC in Ionide fairly often, without any timeline, so the smaller features needs to make sense standalone without other parts. If something works only together with other features you want to add then go for a bigger PR, if something works just fine alone (like improvements in this PR) then small PRs are way to go

@enricosada

Copy link
Copy Markdown
Contributor

I'll review later tonight

@enricosada enricosada left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added some feedback.

i think we should try to minize deps, or do it out of process.

|> List.filter (fun arg -> arg <> "--")

"--simpleresolution" :: "--targetprofile:netstandard" :: "--nowin32manifest" :: args
|> List.toArray No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we discuss about it?
mostly i'd like to avoid the deps on FAKE/paket and transitive (mono.cecil) because these constraint us later.
If we can minimize the surface, better.
we can use paket github refs to the fake .fs, or create an ah hoc assembly
Or use it out of process, as console app, so who care about deps.

if is a script initialization thing (paket), i'd like to move it in DPW.
so every fsx load support the nuget paket syntax OOTB

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd like to avoid the deps

I'm not sure if we have a problem here. FAKE is important, getting good UX in FSAC/Ionide seems really important from my point of view.
Also, FAKE is well maintained and regularly released project so it would bottleneck us on releases, and @matthid said he'd be open to giving us release rights for the packages we need.

I'd be in favor of merging this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I am in favor too.
There is no problem, and don’t think we’ll get stuck.

And it’s lovely to have FAKE supported ootb.

Just trying to figure out if we can somehow minimize deps.
If not, that’s it, not hard feeling.

Maybe the only thing is that because is just a fsx -> fsharpprojectiption I’d like to move that logic in DPW, so:

  • is easier to test
  • works if anyone want to get the options for a fake script

I need anyway to complicate it a bit the fsx initalization to support in DPW some scenarios (choose tfm, dotnet fsi vs fsi)

But I can refactor our later, np

@matthid

matthid commented Jun 12, 2019

Copy link
Copy Markdown
Contributor Author

i think we should try to minize deps, or do it out of process.

Yes technically it is possible and a good idea for sure, but I think really expensive (coding time) as well. Also, it will make us move very slowly. Maybe we can reconsider this after we have figured out how everything works and what our integration points are. I think this PR already encapsulates that by starting a new FakeSupport module.

Note: For listing targets in the outline (or some other features I have in mind) I already need to spawn external processes because of assembly-locking. Maybe this is then an opportunity to split this out as well (no promises ;))

On the other hand, it will cost performance as well. Spawning another process is not the fastest thing in the world. Especially on windows (though it seems to get better)

i'd like to move it in DPW. so every fsx load support the nuget paket syntax OOTB

How is that project related to this? I don't think I understand. There is no project file involved here?

Btw. I waited for the general #load "<prov>" feature, and waited, and waited. I think especially for FAKE-scripting we waited long enough. Lots of users expect this stuff to just work and a lot of bad impression for FAKE 5 is because of tooling (see screenshots above). Sorry, I'm a bit tired ;)

@enricosada

Copy link
Copy Markdown
Contributor

How is that project related to this? I don't think I understand. There is no project file involved here?

DPW is going to be the lib who gather the project system info (FCS initialization options, solution explorer info, installed .net locations, etc).
The fsx are just a special case where the FCS initialization options (references, source files, etc) are read from the fsx instead of the fsproj.

In you diff, you change the FCS options after are read in

let! projOptions = fsxBinder.GetProjectOptionsFromScriptBy(targetFramework, file, source)

my idea is to move that initialization logic inside that, maybe modifying it a bit

fsxBinder.notification |> Event.subscribe .. // subscribe to notifications, like restore started, etc

// initialize options and restore packages as needed
do! fsxBinder.InitializeProjectOptionsFromScriptBy(targetFramework, file, source)

// get fcs options
let projOptions = fsxBinder.GetProjectOptionsFromScriptBy(file)

@matthid

matthid commented Jun 12, 2019

Copy link
Copy Markdown
Contributor Author

I just would like to add:

we can use paket github refs to the fake .fs, or create an ah hoc assembly

I don't think we will get far with this approach, we definitely need to do external process and some IPC magic (either webserver or just stdin/out). The reason is that while I only added a few lines they actually do a lot behind the scenes and actually need most of the dependencies...

@enricosada

Copy link
Copy Markdown
Contributor

yes, 👍 for the out of process.

@Krzysztof-Cieslak

Copy link
Copy Markdown
Member

If we want to do out of process and IPC then LSP with custom endpoints is good communication protocol ;-) we’re already doing it for Background Service

@matthid

matthid commented Jun 12, 2019

Copy link
Copy Markdown
Contributor Author

I think I will look at the suggested refactoring (moving the code to the DPW, which wasn't there when I started the PR, only after the merge). But the rest will follow on separate PRs. Out of process only when there is a technical need (ie later). This is because I think this PR will already improve the situation a lot as it is today. Even without change detection you can just reload/reopen the script and it will be fine.

It shouldn't touch "regular" scripts but if people report issues should be able to easily revert this or make the isFakeScript function return always false.

@enricosada

Copy link
Copy Markdown
Contributor

Feel free to leave the code here, i’ll refactor out in DPW later

@enricosada
enricosada merged commit 774647d into ionide:master Jun 13, 2019
@enricosada

Copy link
Copy Markdown
Contributor

merged, thanks @matthid !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants