Nova

Extensions


Readme

JavaScript for Automation (JXA) extension for Nova

Make Nova your editor of choice when developing JavaScript for Automation (JXA) scripts.

Features

  • Syntax highlighting for JXA globals and ObjC bridge idioms.
  • Proper symbolication of the above, including integration into the Symbols pane.
  • Completions for JXA globals’ methods and properties.
  • Configurable script build and run task templates based on osacompile and osascript.
  • Optional linting of JXA files on save or on change, through ESlint if it is configured for your workspace, else through osacompile.
  • Commands to send the current file or current selection to the macOS Script Editor. Note you will be prompted by macOS to grant Nova the right to automate Script Editor the first time you run this.
  • German localisation.

A note on linting

This extension does not try to provide a full-fledged ESLint experience. In fact, there would be no ESLInt functionality at all if the relevant extension worked reliably for JXA files (see below in the *Caveats section). As such, installing and configuring ESLint for your project is entirely up to you: the extension simply picks up what is configured anyway.

If you’d rather not go through the motions of doing that for your JXA project, the extension will fall back on osacompile for linting: be aware that this is bare bones at best, as it will only report parsing errors (the first parsing error only, to be precise). If you need to check your coding style, configure ESLint to work with your JXA files (my shareable JXA ESLint config might help).

Screenshots

Autocomplete, syntax highlighting and symbolication of JXA and ObjC bridge idioms:

Linting with ESLint:

Build task settings (showcasing German localisation):

Caveats

Currently, there are some oddities you will encounter using this extension you should be aware of:

  • The JXA syntax is declared as a sub-syntax of JavaScript; Nova does the right thing and activates extensions claiming to process JavaScript on JXA files. Some of these extensions will still fail to work with JXA files, others will be unreliable. A notable examples of the former is the TypeScript Language Server, one of the latter the ESLint extension. Workaround: temporarily switch to JavaScript via Nova’s syntax picker; for ESLint, use JXA’s own support for it.
  • When the regular ESLint extension works, it contributes its own set of issues to the Problems pane, which duplicate JXA’s. This mostly only happens for the first active editor window in the workspace, if at all. Workaround: close the affected tab, then re-open that file. Usually, the ESlint extension will fail to pick that up and thus not contribute duplicate issues again. Alternately, there is an option to disable JXA’s own ESLint functionality in the extension preferences.
  • Syntax highlighting of ObjC constructs seeps into nominally atomic scopes like strings and comments (no workaround ATM).

Hop over to the issues if you have advice to contribute on any of these issues.

Caveats for users of elder Nova versions

The following issues have been resolved in current versions of Nova. They are listed for compatibility reasons with elder Nova versions that might stick around when users decide not to pay for updates: - Nova versions 1.0 through 1.2: Syntax highlighting does not always update when the JXA syntax is applied to an already open file (be it through the syntax picker, or because the extension was installed while the file was open). Workaround: open Nova’s preferences and switch your theme to another, then back (you don’t need to close preferences for this to take effect). This will refresh syntax highlighting.


Changelog

Version 1.4.0 and 1.4.1

Added:

  • Option to globally disable JXA’s ESLint functionality (i.e., lint with osascompile only) in the extension settings.
  • Issues reported by osacompile are now correctly showing their source as “osacompile”.

Fixed:

  • Issues displayed in the Problems pane would stick around after the document they refer to was closed.
  • The osacompile linter would not actually check for the presence of an executable for the wrapper script it needs.

Fixed in 1.4.1:

  • Incoherent README “Caveats” section.

Other changes:

  • Asynchronous linter management has been refactored, greatly simplifying the linter modules proper.

Important notice: I’ve finally figured out why the first open JXA text editor often reports duplicate ESLint issues. Unluckily, I cannot fix this, as that is the “official” ESLint extension doing its part (see the “Caveats” section int the README).

Version 1.3.0

This release enables Nova’s auto-formatting features for JXA files. For some reason, I assumed this would be inherited from the parent syntax (i.e. JavaScript). I was wrong.

Added: - Support for auto-indentation of JXA code. - Support for commenting and uncommenting JXA code. - Support for bracket functionality in JXA code. - Support for surrounding pairs in JXA code.

Version 1.2.1 and 1.2.2

Hotfix releases: the extension activation sequence was failing when the extension was not in ad-hoc (developer) mode, which left commands and linting functionality non-functional. The whole sequence is now more robust and should notify users when something went wrong while activating. It should also be slightly faster, as the check for the executable status of the included binaries is now performed asynchronously.

Version 1.2.0

This is a spit-and-polish release. Behind the scenes, the linting functionality has been entirely refactored, but what you should notice from that is mainly that it works better.

Added:

  • Linters add informative entries to the Problems pane (but only when “real” issues are found). See the screenshot in the README for an example.
  • The Problems pane shows an information message when no linter is available for the open source file.
  • The display of informative pseudo-issues (like the two mentioned above) can be disabled globally.
  • The stripping of the original source extension when building can be disabled in the task settings.
  • A command in the Extensions menu to open the extension’s workspace preferences.

Fixed:

  • The Problems pane could display duplicated issues for the editor that was active when the extension activated.
  • Issues displayed in the Problems pane when using on save linting could stick around indefinitely when switching to linting on change.
  • ESLint would try to lint files originating outside the workspace, which would fail or have unexpected results (rules are path specific). The extension now falls back to osacompile instead.
  • Retrieving a local configuration value derived from a global value would fail for boolean values.

Other changes:

  • ESLint linting now directly parses the JSON output. The custom formatter has been removed. As it turns out, that is what all ESLint CLI formatters actually do, so we might as well cut out the middle person.

Version 1.1.0 and 1.1.1

The tentpole feature of this release is ESLint based linting of JXA files. This simply picks up your existing ESLint configuration and falls back to osacompile if there isn’t any. It will hopefully alleviate the fact that the current ESLint extension doesn’t work with JXA files; the JXA extension doesn’t try to provide the same level of features, though.

Added:

  • ESLint based linting of JXA files. See the README’s A note on linting section for details.
  • Cascading settings: extension options can now be set at the global level and at the workspace level, with the latter inheriting from, or overriding, the former.

Fixed in 1.1.1:

  • A glitch in the README’s A note on linting section.

Version 1.0.3

Hotfix release: correct links to repository and issue tracker.

Version 1.0.2

Fixes:

  • Source code containing escape characters (e.g. \n) in strings, comments and regular expression literals getting mangled when passed via selection to a run task, or when passed to the macOS Script Editor.
  • Menu entries for commands not ending with an ellipsis despite opening another app.

Other changes:

  • Improved error handling in case the directory used in validation is not accessible.

Version 1.0.1

Hotfix release: ensure included binaries are executable. Fixes tasks, commands and validation failing in 1.0.0.

Version 1.0.0

Initial release:

  • Syntax highlighting for JXA globals and ObjC bridge idioms.
  • Proper symbolication of the above, including integration in the Symbols pane.
  • Completions for JXA globals’ methods and properties.
  • Configurable script build and run task templates based on osacompile and osascript.
  • Optional validation of JXA files through osacompile, on save or on change.
  • Commands to send the current file or current selection to the macOS Script Editor.

License

This project is provided under the MIT license:

Copyright © 2020 Martin Kopischke.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.