Skip to content

Latest commit

 

History

History
70 lines (37 loc) · 9.48 KB

README.md

File metadata and controls

70 lines (37 loc) · 9.48 KB

Go Nova Extension Logo

Go Language Definition for Nova

An attempt to build a Go language definition for the Panic Nova editor.

My personal thanks to the major contributors of this project, without whom this extension would never been working:

Additionally, much of the more intricate and obscure issues have been solved by shamelessly copying code from:

Note: This is still an alpha version with reasonably working syntax highlighting and some extra goodies from using the Language Server Protocol, but it is plagued by unstability issues and frequent crashing. See below for some guidelines.

Installation

Once activated, files ending in *.go should automatically be recognised (and formatted) as Go language files. Similarly, *.tmpl Go template files will also be recognised1.

In either case, additional Go specific features are available by installing the Go Language Server, gopls.

If you use Homebrew to install your packages, all you need is to type:

brew install gopls

If not, you can install it as described here.

Then tick the Enable Language Server checkbox in the Preferences for this extension. If gopls is (correctly) installed in your search PATH, the extension should find it. If it is elsewhere, set that where in the Preferences for this extension as well. Note that Nova's language server support and gopls are both new and evolving. Many things don't work quite right yet2.

Disclaimers

I'm a bit clueless about how the syntax highlighting engine/parser actually parses the language files. There is next-to-zero 'official' documentation; however, on the site for an editor made by a competitor, it looks like they have used something very similar, and — allegedly! — based on the original Coda syntax (not Coda 2!). Apparently, Nova uses a variant of the same parser 'family'.

This version includes a Go.xml Syntax template which was cobbled together out of a lot of sources, namely, the Coda 2 Go language definition files; the Nova (included) language files for PHP, TypeScript (because Go is also strongly typed), JavaScript; and the extraordinary (but sadly incomplete) work made by @ambelovsky on GitHub, when adapting the old Coda syntax for the editor from the competition. Several of his comments have been copied and incorporated. His work was sadly not complete, still had a lot of errors (basically he used the template for JavaScript), and, at the date of writing, was abandoned eight years ago. It still had lots of very interesting structures to parse the Go language (while leaving several others unimplemented). While strongly inspired by his work, this is not merely a copy & paste — many adaptations were required to get at least some of the functionality to actually work. Most doesn't (it gets silently ignored) and I still haven't figured out how to deal with them...

Additionally, I've included a Syntax template for Go Templates. It's almost exactly the same as the syntax for Smarty templates (which I have been using) with some tiny changes, which I hope to have correctly implemented.

Although the current version includes a Completions file, I don't see any kind of completion happening (except for closing braces). I've tried to figure out how the syntax of the Completions file works, but it's even more obscure (to me) than the actual Syntax file. The two are also possibly related — through common identifiers — but I fail to understand exactly how the two 'play' together.

Also, Nova — unlike Coda — allows extensions to use the Language Server Protocol (like their closest competitors do), a Microsoft-promoted effort enabling a 'write once, reuse often' philosophy for writers of syntax checkers. In other words, the hard work is put into creating a functioning LSP 'server' (basically an application that reads a file in a specific language, or parts of a file, and figures out if it has any syntax errors) by the community of syntax checkers. Then editor plugins (of all kinds, not only desktop apps) can interface with such a server in order to get syntax checking. In theory, it's a very easy way to quickly expand the ability for a code editor to accept gazillions of languages without requiring the developers to spend days and nights coding as many syntax checkers as possible. With new languages coming up all the time, many becoming fashionable for a few years and disappearing shortly afterwards, this method ensures that editor developers are not wasting their precious time. It also means that updating syntax checkers for upcoming new versions of a specific language will not require any coding — just upgrade the LSP server. And, finally, it also means that all code editors will check syntax in the same, predictable way (and also that all will get upgraded to the latest version of the syntax almost immediately), which means that, if you switch editors, the 'new' editor will already support the latest version of your favourite programming language and syntax checking will work in pretty much the same way...

Therefore, this extension tries to use the official (Google-supported) Go Language Server if you install it as described in the Installation section above.

This is still very quirky. Microsoft developed the LSP specifically for Visual Studio Code, their free, open-source, cross-platform editor, thus allowing non-Microsoft-specific languages to be as easily integrated with their editor. However, the Microsoft specifications are very Microsoft-centric, and the Google team behind gopls grumbles and complains about several ambiguous descriptions in the protocol, and the choices they've made to implement the (complex) specifications. Sadly, though, those specifications are very Google-centric (notice the pattern?) and they don't match easily with the Microsoft ones. And on top of all that, we have to deal with Panic's own implementation of LSP support — which is (at the time of writing!) a bit obscure, a bit opaque, and not exactly super-well-documented (namely, at least for me, it's not obvious what Nova does on its own and what the extension developer has to do). We have to take hints from others who travelled the same road and try to figure out how they've done it.

Note that Nova logs some language server interaction in the Extension Console, and if you run the extension in "developer mode" (see the Extension Development item in Nova's General preferences) gopls will write logs to /tmp/gopls.log but these can be a bit cryptic.

In conclusion: all of the above is really a work in progress — or rather, a lot of work in progress. There is far less functionality which actually does anything than lots of files with rules that are supposed to do something but... don't. Therefore, caveat utilitor.

Suggestions and bug reports are more than welcome, but please take into account that I'm new to all of this, and might not be able to even understand most of your issues, much less fix them! But I'm learning...

Well-known bugs

  1. Right now, the one that baffles us most is why we are getting Markdown from gopls but somehow Nova is confused and renders it as plain text (which is... weird). There are options to make gopls change from Markdown to plain text — so that Nova might at least display a simple one-liner, albeit unformatted — but it seems hard to figure out how to pass that option from Nova to gopls in a way that gopls understands.
  2. The extension crashes a lot, especially when in Development mode. There are no 'obvious' errors showing up on the console or the error logs, so this has been hard to track down (I suspect that there is some cleaning up that is missing). If you're plagued with these constant crashes, just uncheck the Enable Language Server checkbox on the Preferences for this extension. You will still get Go syntax highlighting, but the additional goodies provided by LSP will be turned off.
  3. There are a few hooks allowing you to theoretically run some post-formatting tools to comply with Google's style guidelines for Go, as well as a way to check that all imports are properly referenced, etc. With this version, there is no documentation yet for how to activate those extra features, but hopefully this will be addressed in the very near future... fingers crossed!

My GPG Fingerprint

In case you need it to send me encrypted emails:

CE8A 6006 B611 850F 1275 72BA D93E AA3D C4B3 E1CB


1 I based that parser on the PHP Smarty templates — Go's syntax is similar.

2 A notable example is that for some reason the Markdown emitted by gopls is not understood by the Nova editor, which is quite strange, since other LSPs (namely, @apexskier's TypeScript Extension) have no such problems.