Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2

[*.json]
indent_size = 2
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
# ^ added for shellcheck and file-type detection
use flake
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
out/
37 changes: 37 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"root": true,
"extends": [
"eslint:recommended",
"plugin:eslint-comments/recommended"
],
"plugins": [
"unused-imports",
"simple-import-sort"
],
"rules": {
"prefer-spread": 2,
"no-useless-concat": 2,
"prefer-template": 2,
"no-useless-rename": [2],
"object-shorthand": [2, "always"],
/* unused-imports */
"unused-imports/no-unused-imports": 2,
/* simple-import-sort */
"sort-imports": 0,
"simple-import-sort/imports": 2,
"simple-import-sort/exports": 2
},
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@typescript-eslint/recommended"
],
"plugins": [
"@typescript-eslint"
],
"parser": "@typescript-eslint/parser",
"rules": {}
}
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ out
node_modules
.vscode-test/
*.vsix
.direnv/
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ jobs:
- set -e
# publish the extension to the Marketplace
- vsce publish -p $VS_MARKETPLACE_TOKEN

16 changes: 10 additions & 6 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"eg2.tslint"
]
}
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"jnoortheen.nix-ide",
"arrterian.nix-env-selector",
"tamasfe.even-better-toml",
"jkillian.custom-local-formatters",
"dbaeumer.vscode-eslint"
]
}
65 changes: 36 additions & 29 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,40 @@
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "npm: watch"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "npm: watch"
}
]
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": {
"type": "npm",
"script": "watch"
}
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": {
"type": "npm",
"script": "watch"
}
}
]
}
51 changes: 42 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
}
"nixEnvSelector.nixFile": "${workspaceRoot}/shell.nix",
"typescript.tsdk": "node_modules/typescript/lib",
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"customLocalFormatters.formatters": [
{
"command": "treefmt -q --stdin ${file}",
"languages": [
"typescript",
"json",
"jsonc",
"md",
"nix",
"toml"
]
}
],
"[toml]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[nix]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[json]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[jsonc]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[md]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"[typescript]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
}
}
32 changes: 16 additions & 16 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "always"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "always"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
2 changes: 1 addition & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ vsc-extension-quickstart.md
**/tslint.json
**/*.map
**/*.ts
.travis.yml
.travis.yml
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Change Log

All notable changes to the "vscode-dhall-lsp-server" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [0.0.2]

- Add dhall-to-json, dhall-to-bash, dhall-to-text and dhall-to-yaml preview

## [0.0.1]
- Alpha release. Only basic diagnostics on save is working.

- Alpha release. Only basic diagnostics on save is working.
35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
## vscode-dhall-lsp-server

This is a [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) VSCode plugin for the [Dhall](https://dhall-lang.org) programming language.

![](./images/screencap.png)

# Dhall language support in VSCode/ium

The Dhall language integration consists of the following parts:
- The VSCode/ium plugin "Dhall Language Support" *([vscode-language-dhall](https://github.com/dhall-lang/vscode-language-dhall))* adds syntax highlighting for Dhall files.
- The VSCode/ium plugin "Dhall LSP Server" *([vscode-dhall-lsp-server](https://github.com/dhall-lang/dhall-haskell/tree/master/dhall-lsp-server))* implements the LSP client – yes, there is a naming issue here – that communicates with the backend via the [LSP protocol](https://microsoft.github.io/language-server-protocol/specification) to provide advanced language features like error diagnostics or type information, etc.
- [*dhall-lsp-server*](https://github.com/dhall-lang/dhall-haskell/tree/master/dhall-lsp-server), which is part of the [*dhall-haskell*](https://github.com/dhall-lang/dhall-haskell) project, implements the actual LSP server (i.e. the backend) that implements those language features in an editor agnostic way, though at the moment only a VSCode/ium frontend exists.

- The VSCode/ium plugin "Dhall Language Support" _([vscode-language-dhall](https://github.com/dhall-lang/vscode-language-dhall))_ adds syntax highlighting for Dhall files.
- The VSCode/ium plugin "Dhall LSP Server" _([vscode-dhall-lsp-server](https://github.com/dhall-lang/dhall-haskell/tree/master/dhall-lsp-server))_ implements the LSP client – yes, there is a naming issue here – that communicates with the backend via the [LSP protocol](https://microsoft.github.io/language-server-protocol/specification) to provide advanced language features like error diagnostics or type information, etc.
- [_dhall-lsp-server_](https://github.com/dhall-lang/dhall-haskell/tree/master/dhall-lsp-server), which is part of the [_dhall-haskell_](https://github.com/dhall-lang/dhall-haskell) project, implements the actual LSP server (i.e. the backend) that implements those language features in an editor agnostic way, though at the moment only a VSCode/ium frontend exists.

# Installation

Expand All @@ -20,33 +22,34 @@ The "official" releases can be installed as follows:

## Installing the latest development versions

**Note ** The versions of *vscode-dhall-lsp-server* and *dhall-lsp-server* need not necessarily match: an older client version will simply not expose all commands available in the backend, while an older server might not implement all commands exposed in the UI.
**Note ** The versions of _vscode-dhall-lsp-server_ and _dhall-lsp-server_ need not necessarily match: an older client version will simply not expose all commands available in the backend, while an older server might not implement all commands exposed in the UI.

**vscode-dhall-lsp-server**
1. You need to have *npm* installed (e.g. using your favourite package manager).

1. You need to have _npm_ installed (e.g. using your favourite package manager).
2. Clone `[email protected]:dhall-lang/vscode-dhall-lsp-server.git` into a folder under `~/.vscode-oss/extensions/` (or `~/.vscode/extensions/` if you VSCode rather than VSCodium).
3. Inside the checked out folder run `npm install` to fetch any dependencies.
4. Start (restart) VSCode/ium.

**dhall-lsp-server**
1. You need to have *stack* installed.

1. You need to have _stack_ installed.
2. Clone `[email protected]:dhall-lang/dhall-haskell.git`.
3. Inside the checked out repository run `stack install dhall-lsp-server`.


# Usage / Features

- **Diagnostics **
Every time you save a Dhall file it is parsed and typechecked, and any errors are marked. You can hover over the offending code to see the error message; to see a detailed explanation in the case of type errors, click the *Explain* link in the hover box.
Every time you save a Dhall file it is parsed and typechecked, and any errors are marked. You can hover over the offending code to see the error message; to see a detailed explanation in the case of type errors, click the _Explain_ link in the hover box.

- **Clickable imports **
As long as the file parses successfully, all (local file and remote) imports will be underlined and clickable.
As long as the file parses successfully, all (local file and remote) imports will be underlined and clickable.

- **Type on hover **
You can hover over any part of the code and it will tell you the type of the subexpression at that point – if you highlight an identifier you see its type; if you highlight the `->` in a function you will see the type of the entire function. This feature only works if the code passes the typechecker!
You can hover over any part of the code and it will tell you the type of the subexpression at that point – if you highlight an identifier you see its type; if you highlight the `->` in a function you will see the type of the entire function. This feature only works if the code passes the typechecker!

- **Code completion **
As you type you will be offered completions for:
As you type you will be offered completions for:
- environment variables
- local imports
- identifiers in scope (as well as built-ins)
Expand All @@ -56,26 +59,28 @@ As you type you will be offered completions for:
This is the only feature that works even when the file does not parse (or typecheck).

- **Formatting and Linting **
Right click and select "Format Document" to run the file through the Dhall formatter. The command "Lint and Format" can be selected via the *Command Palette* (Ctrl+Shift+P); this will run the linter over the file, removing unused let bindings and formatting the result.
Right click and select "Format Document" to run the file through the Dhall formatter. The command "Lint and Format" can be selected via the _Command Palette_ (Ctrl+Shift+P); this will run the linter over the file, removing unused let bindings and formatting the result.

- **Annotate lets **
Right-click the bound identifier in a `let` binding and select "Annotate Let binding with its type" to do exactly that.
Right-click the bound identifier in a `let` binding and select "Annotate Let binding with its type" to do exactly that.

- **Freeze imports **
Right-click an import statement and select "Freeze (refreeze) import" to add (or update) a semantic hash annotation to the import. You can also select "Freee (refreeze) all imports" from the *Command Palette* to freeze all imports at once.
Right-click an import statement and select "Freeze (refreeze) import" to add (or update) a semantic hash annotation to the import. You can also select "Freee (refreeze) all imports" from the _Command Palette_ to freeze all imports at once.

Note that this feature behaves slightly differently from the `dhall freeze` command in that the hash annotations are inserted without re-formatting the rest of the code!

# Developer notes

**dhall-lsp-server**

- You can also use `stack build dhall-lsp-server` and point `vscode-dhall-lsp-server.executable` in the VSCode/ium settings to the stack build directory, to avoid overriding the installed version of the LSP server.
- You can use standard `Debug.Trace`/`putStrLn` debugging; the output will show up in the "Output" panel in VSCode/ium.
- To log all LSP communication set `vscode-dhall-lsp-server.trace.server` to `verbose` in VSCode/ium.

**vscode-dhall-lsp-server**

- Instead of working in `~/vscode-oss/extensions/...` directly, you can open a clone of the git repository in VSCode/ium and use the built-in debugging capabilities for extensions: press F5 (or click the green play button in the debugging tab) to launch a new VSCode/ium window with the modified extension (potentially shadowing the installed version).
- To package a release:
1. Use `npm install -g vsce` to install the *vsce* executable. I recommend running `npm config set prefix '~/.local'` first to have npm install the executable in `~/.local/bin`; this avoids having to use sudo and polluting the rest of the system.
1. Use `npm install -g vsce` to install the _vsce_ executable. I recommend running `npm config set prefix '~/.local'` first to have npm install the executable in `~/.local/bin`; this avoids having to use sudo and polluting the rest of the system.
2. Run `vsce package` inside the git repo to package the extension, resulting in a file `vscode-dhall-lsp-server-x.x.x.vsix`.
3. You can install the packaged extension directly by opening the `.vsix` file from within VSCod/ium.
13 changes: 13 additions & 0 deletions devshell.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[devshell]
name = "vscode-dhall-lsp-server"
packages = [
"alejandra",
"dprint",
"nodejs-16_x",
"dhall",
"dhall-lsp-server",
]

[[commands]]
package = "treefmt"
category = "formatter"
Loading