pq / scry

a lightweight lua language server for norns.
1 stars 0 forks source link
lua monome norns

scry

a lightweight lua language server for norns.

advises

scry flags syntax errors, identifies common control and data flow issues, highlights implicitly defined globals, overwritten or mutated protected norns global state, unused or shadowed variables and more. behind the scenes scry uses lua_check for linting and analysis and provides all of it’s supported warnings.

alt text

mends

scry builds on the lua_code_formatter to provide simple on-demand code formatting for selections or entire documents.

alt text

sees

(planned) scry provides access to lua and sc docs.


implementation

scry runs as a small lightweight server process. maiden connects to scry via a web socket.

the smarts of scry are written in lua and leverage proven modules. scry is tiny, scalable and simple to extend.

motivation and background

maiden uses a customized ace editor mode to provide an editing experience tailored to lua for norns. out of the box, ace provides basic client-side syntax highlighting and a web-worker-based syntax checker.

the design of ace only allows for limited customization. notably, the syntax checker is not easily enhanced or replaced. work on the client-side has fundamental limitations as well. doing semantic analysis in the browser (to provide, for example, awareness of norns functions or offer lua linting), is not practical. nor is rich code transformation (such as formatting or refactoring). scry works around these shortcomings by migrating analysis to a lightweight server process.

features

beyond the basic ace editor lua support, scry adds:

planned improvements include:

more ambitiously, another mode ("see") for

running scry

running scry involves setting up two parts.

scry server. a process that manages a web socket that serves requests to “advise” and “mend” to maiden.

scry maiden. a version of maiden, tailored to listen to advice from a scry server.

trying out scry involves running a local scry server and local maiden dev server instance. maiden will point to matron and sc repls on your norns device so you can edit and run your scripts in dust.

scry server

get the source. clone or download the scry repo.

setup. first you’ll need to get some lua libraries installed to do the heavy-lifting:luacheck (for static analysis) and lcf (for formatting).

run.

  1. make sure you have lua installed locally (e.g., on mac os, brew update; brew install lua)
  2. the default installation also provides luarocks, a lua package manager. use it to install our library dependencies: luarocks install luacheck; luarocks install lcf

scry needs a server process to manage the web-socket connection w/ maiden. included is a simple server using node. (to be replaced.)

  1. make sure node is installed (on mac os, brew install node)
  2. use the node package manager to add a simple web socket library: npm install --save ws

finally, start scry:

node server.js

(you’ll want to keep this open in a dedicated terminal window or tab — aside, if you’re on mac os, consider the excellent free terminal replacement iTerm2.)

scry maiden

get the source. check out the scry branch of my maiden fork for a version of maiden that integrates with scry. follow the steps in the general maiden README to install deps, etc.

run.

  1. be sure wifi is enabled on norns (system > wifi menu)
  2. note the ip address (visible in the wifi menu once connected); alternatively if norns.local resolves for you (ping norns.local), prefer that.
  3. update app/public/repl-endpoints.json replacing maiden_app_locationto point at your norns ip address. (here on we’ll use norns.local)
  4. mount your norns locally (on mac os, sshfs we@norns.local: ~/norns-mnt)
  5. (in a terminal window) start the backend: go build && ./maiden -app app/build/ -data ~/norns-mnt/dust -doc ~/norns-mnt/norns/doc -debug
  6. (in another terminal) start the dev server: cd app; yarn start
  7. point your web browser at the dev server: http://localhost:3000/

next steps