Polar LSP: A Little Help with the Rules

Most of the engineering staff at Oso uses Language Server Protocol (LSP) implementations in their editors––Rust, TypeScript, and others all have fantastic LSP implementations that make the hard work of building software a bit easier. If you're not familiar, the Language Server Protocol is a specification that lets people write rich developer tooling in an editor-agnostic way.

We knew that building our own LSP implementation for Polar policy files would go a long way to making Oso the absolute easiest way to write your authorization logic––and today we're pleased to announce it's shipped and widely available.

While the Polar LSP includes the general features you expect like syntax validation, we also have two additional, powerful, Polar-specific features:

Shorthand expansion

When writing Polar policies, users can write ergonomic “shorthand rules,” which greatly simplifies common types of rules tying together your roles, permissions, and inter-resource relations. 

Behind the scenes, we convert these shorthand rules into “longhand.” This process has been a bit mysterious (though it is explained in detail in our docs).

To make this process more clear, when using the Polar LSP, we’ll show you the longhand version of the rule when hovering over the shorthand.

screenshot of a hovering over a shorthand rule in Polar and a window displaying the longhand version of the rule

Unit test integration

Polar policies include built-in unit tests, which let you set up a small set of facts and assert that rules produce certain outcomes based on those facts.

To help you run and manage those unit tests, the LSP now lets your unit tests directly from your editor. If any of your tests fail, the LSP will suggest facts that you can introduce to get the tests passing.

screenshot of a failed Polar unit test being hovered over suggesting Quick Fixes to make the test pass

Using the LSP

One of the most ingenious features of the Language Server Protocol is that it’s editor-agnostic. How to get the LSP working for you depends on your environment:

VSCode

As of version 0.39.0, the Oso VSCode extension is powered by the Polar language server. You can install it through the Extensions panel of VSCode.

Vim, Emacs, etc.

If you use editors other than VSCode, you can run the LSP through the oso-cloud binary, using:

oso-cloud lsp

On the web

Oso Cloud’s policy editor in code mode leverages the Polar LSP by default. It’ll be available as soon as you log in.

What would help you most?

This is just the beginning. We hope to keep adding features (such as refactoring support) to the Polar language server. Is there a feature you're particularly interested in? Let us know!

If you haven’t checked out Oso Cloud yet, you can sign up for a free developer account here.

Want us to remind you?
We'll email you before the event with a friendly reminder.

Write your first policy