Flow-for-vscode: Feature request: Custom language

Created on 23 Nov 2017  路  8Comments  路  Source: flowtype/flow-for-vscode

I'm wondering if it would make sense for this extension to register itself as a new language in vs code.

It could include the babel grammar from https://github.com/gandm/language-babel and support all the flow syntax.

I've been working for a couple of month with an extension that define it as a new language and it's a trade off, but I like it better.

Plus

  • It's faster as the javascript vscode engine is not running in the background.
  • the completion is not polluted with vscode fuzzy completion
  • there is no popup showing 2 times the same definition when doing a go to definition
  • you don't have to disable the javascript.validate.enable option

Minus

  • Other extensions binded on the javascript language have to know about the new language or offer an option to specify a custom language
  • Some builtin vscode javascript features are helpful like the import file completion, but they could always be re-implemented in the extension.

Another option could be to create an second extension that define a language javascriptflow and have this extension support "javascript", "javascriptreact" and "javascriptflow"

What do you think?

I modified this extension to add a new language here, if anybody want to test: https://github.com/ericm546/flow-for-vscode/blob/master/flow-for-vscode-new-language-0.0.1.vsix

Most helpful comment

@paul-russo You should use the Babel-Javascript by Michael McDermott for the syntax highlighter and grammar. It's far far better than vscode's default. I get the correct syntax highlighting while using that plugin (in fact, the first one is wrong in that case 馃槈):

image

All 8 comments

It does sound like a good idea overall, it feels like something that would break a lot of people's setups overnight - which is obviously worrying.

I've been hesitant with working on this kind of idea, because I know it'd be a support nightmare (I've not worked on a flow project in months) but if you're willing to take over on handling issues, I'm willing to give it a shot.

Came here because of #225. Not being able to use generics on arrow functions is a bummer. Not really sure what all is involved with creating a custom language, but wanted to register my support and offer whatever little assistance I can... which is probably not much :(

In the meantime, if anyone else runs into this the same way I did. You can get around this by using regular old anonymous functions like this:

function<T>(p: <T>): T { return p; }

Just to add my support for this too

As in you're going to start working on in @covertbert ?

Apologies I just meant that I would support it being worked on by someone (I know that's not helpful at all for you). While I'd love to contribute I'm not sure I have anything like the knowledge required although I could certainly try!

@chasingmaxwell Another quicker (and dirtier) fix for the syntax highlighting issue with generics is to add a "closing tag" in a comment, to trick VSCode's JS syntax highlighter:

const example = <T>/* </> */(x: T): T => whatever(x);

Obviously not pretty, but if you want to just have syntax highlighting for the rest of the file while you're working on it, it should do the trick.

@paul-russo You should use the Babel-Javascript by Michael McDermott for the syntax highlighter and grammar. It's far far better than vscode's default. I get the correct syntax highlighting while using that plugin (in fact, the first one is wrong in that case 馃槈):

image

@kumarharsh thank you!! For anyone reading the above worked perfectly for me ^^

Was this page helpful?
0 / 5 - 0 ratings