idleberg / vscode-applescript

Language syntax and snippets for AppleScript
https://marketplace.visualstudio.com/items?itemName=idleberg.applescript
MIT License
70 stars 8 forks source link

Does This Extension Fully Support JavaScript Code Completion in JXA file? #7

Closed JMichaelTX closed 5 years ago

JMichaelTX commented 6 years ago

I'm getting mixed results trying to answer that question.

I have one file where it auto-completes for the "repeat" function, but it does not in another file. I just figured it out. If offers auto-complete if that function had been previously used.

So, it appears that real, full JavaScript code completion is not supported. Is there some way, with some other extension or setting, we can get this? JavaScript code completion is the main reason I use VSC for coding JavaScript, and JXA.

idleberg commented 6 years ago

I’m afraid I cannot answer that until I get back home in early May

idleberg commented 6 years ago

Other editors – Sublime Text, TextMate or Atom – inherit the syntax scope from its parent, so source.js snippets would work in source.js.jxa. It's beyond me why this doesn't work the same in VScode.

johnelm commented 6 years ago

Hi @idleberg .. I can't confirm it now, but I looked into this a couple weeks ago and I was thinking that in vscode, the source.js tmLanguage identifier was providing syntax coloring, and that other mechanisms from the language server were providing completion etc.. so if you wanted to inherit all the other goodies like code completion, you'd have to extend them as well.

In any case I have this working by treating jxa scripts as plain .js, either by naming them with the .js extension, or adding .jxa to file.associations for JavaScript ( foregoing the vscode-applescript extension, for jxa ). I don't have to compile in vscode so I just use a shebang to run them. See https://github.com/johnelm/node-jxa/issues/26 .

idleberg commented 6 years ago

If language servers make it easier to extend syntax scope, that's probably worth looking into. Otherwise, they bear the same problem.

I will reopen this issue, maybe someone who knows more about the matter is willing to contribute a language server.

TheNewbieWoodworker commented 5 years ago

I hope you're still monitoring this issue. I have a workaround, but I'm wondering if there's anything you can add to your awesome extension which might make my workaround work better.

Here's the workaround:

I do all my editing with Language Mode set to "JavaScript". When I compile/run it, I have a macro that changes the Language Mode to "JXA" before the compile. (The macro is a Keyboard Maestro macro, but it could also be created in one of the Macro extensions).

When the script has finished running, it executes another Keyboard Maestro macro which changes the Language Mode back to "JavaScript". This requires code in the JXA script, so it only works if you're running the script, not just compiling. If anyone cares, I discuss this in detail here: https://forum.keyboardmaestro.com/t/how-to-use-vs-code-for-jxa-with-keyboard-maestro/15281

My point is this:

I'm hoping you can add something to your extension to help change back to JavaScript when it's done compiling/running. Here's some ideas:

1) Obviously the easiest thing for me would be if there was an option to change the Language Mode back to JavaScript (or whatever) when it's done compiling/running.

2) If not that, there's at least one VS Code extension that supports creating macros, and optionally assigning hotkeys to the macros. So if you had an option I could set that can either execute the macro (I don't know exactly how this would work), or "press" a hotkey, when it's done compiling/running, that would work as well.

And perhaps this might give you some other ideas for workarounds, also. Let me know if this makes sense.

Obviously I can continue using my workaround. But if you were able to provide support to switch the language mode when it's done, then the workaround could work without Keyboard Maestro. Instead, it could work using a free VS Code Macro extension. And it wouldn't require special code in the JXA script.

Thanks!

idleberg commented 5 years ago

Today, I found out that JavaScript syntax can be embedded into JXA. This allows using the default JavaScript snippets, but not the completions and tooltips (which, I guess, are) provided by the language server.

The best experience for now is probably enabling the menu icons when working in the JavaScript scope (which the next release does!). Otherwise, I suggest bringing the lack of JXA support in the language server to Microsoft's attention.

TheNewbieWoodworker commented 5 years ago

As far as an editor like VS Code is concerned, there's no difference between JXA and JavaScript. It's functionally the same thing. JXA adds access to some Mac-specific stuff, but it all looks and acts just like JavaScript.

The only real difference (as far as VS Code is concerned) is how to compile and run it. And possibly debug it, but I won't hold my breath for VS Code to support debugging JXA.

So that's why I only need your extension when I want to compile or run my code. And that's why changing the Language Module is a decent workaround.