Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Add try / playground support #84

Open
Gozala opened this issue Mar 14, 2017 · 3 comments
Open

Add try / playground support #84

Gozala opened this issue Mar 14, 2017 · 3 comments

Comments

@Gozala
Copy link
Contributor

Gozala commented Mar 14, 2017

Currently to sketch some ideas I with flow one needs to create a project with flow configuration, for that reason I often time tend to reach over for flowtype.org/try instead. It would be really nice if I were able to type check arbitrary buffers with flow if they are starting with @flow pragma.

@Gozala
Copy link
Contributor Author

Gozala commented Mar 15, 2017

I have being trying to figure out the way to implement this, digging through flow-base code but honestly I'm quite lost.

From what I understand there is hard wired assumption that there is .flowconfig file associated with every file which isn't going to be the case here.

If someone more knowledgeable about the code base could offer a guidance I'd like to take a stab at it. Maybe @nmote ?

@Gozala
Copy link
Contributor Author

Gozala commented Mar 15, 2017

Looking into this further it seems that there is no way to run flow check-contents without specifying a --root which happens to contain .flowconfig. Which I find unfortunate

It seems there is also facebook/flow#389 issue on file with a request to make .flowconfig optional. Maybe @gabelevi has something to say ?

In the meantime I'm considering to add try directory to this repo with a blank .flowconfig and use that as root for this feature.

Gozala added a commit to Gozala/flow-for-vscode that referenced this issue Mar 16, 2017
- Add `playground/.flowconfig` blank file to workaround flow’s requirement to have `.flowconfig` file (see facebook/flow#389)
- Add `playground/try.js` blank file that will be used as file parameter when running `flow check-contents` so that `playground` will be treated as project root & defaults will be used for flow configuration.
- Made changes to flowDiagnostics module so that untitled js documents with @flow pragma are type checked with flow similar to how flowptype.org/try does it.
@Gozala
Copy link
Contributor Author

Gozala commented Mar 16, 2017

So I created pull #88 that implements this functionality. Specifically if you create new tab and set language to js and the code has /* @flow */ pragma, with this changes extension will type check it with flow's default config, reporting problems or succeeding.

Still I think proper solution would be to remove a .flowconfig requirement from flow and also make project root optional. That way no workarounds described in pull request will be necessary. In fact js libraries that wrap flow also seem to have ton of code to just deal with these requirements, so removing it would make everything way simpler.

Now there is one scenario where #88 still won't type check. Say you do draft the code in unsaved buffer and everything is fine, and then you save that buffer into file that isn't under the directory containing .flowconfig and further edits won't be type checked. Main reason is because flow wrapper libraries again do a lot to detect the root and bail when if they can't find it. So application of the same workaround won't really work, at best this workaround could be uplifted to the nuclide libraries but then again actually breaking .flowconfig requirement seems like a much better option.

orta added a commit that referenced this issue Mar 16, 2017
Implement flow support for unsaved docs as per #84
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant