3 sendNotificationWithAction,
4} = require("notifications");
7} = require("download");
10} = require("configuration");
12 getFileName, createEnv, getEnv
15exports.activate = function () {
16 nova.commands.register("stop", (_workspace) => {
19 nova.commands.register("restart", (_workspace) => {
22 nova.commands.register("clear-cache", (_workspace) => {
23 nova.fs.rmdir(nova.extension.globalStoragePath);
26 nova.commands.register("format", formatFile);
29exports.deactivate = function () {
30 // Clean up state before the extension is deactivated
37function formatFile(editor) {
38 // If there is no URI, there's not much we can do ;(
39 if (editor.document.uri) {
40 const name = getFileName(editor.document.uri);
42 const removeNotification = sendNotificationWithAction(
44 "Waiting for Haskell Language Server to format " + name,
50 editor.onDidChange(() => {
56 uri: editor.document.uri,
59 tabSize: editor.tabLength,
63 lspClient.sendRequest("textDocument/formatting", req).then((edits) => {
64 editor.edit((edit) => {
66 const range = new Range(0, editor.document.length);
67 const documentText = editor.document.getTextInRange(range);
68 const newText = applyAllLSPEdits(edits, documentText);
70 edit.replace(range, newText);
79function applyAllLSPEdits(edits, text) {
84 function goToLine(l) {
86 if (text.slice(i, i + 2) === "\r\n") {
89 } else if (text[i] === "\n" || text[i] === "\r") {
98 goToLine(edit.range.start.line);
99 i += edit.range.start.character;
100 out += text.slice(prev, i);
101 goToLine(edit.range.end.line);
102 i += edit.range.end.character;
106 out += text.slice(i);
110async function startServer() {
113 const path = await getServerPath();
114 const env = await getEnv()
115 const serverOptions = {
117 args: ["lsp", "--cwd", nova.workspace.path],
119 const clientOptions = {
120 syntaxes: ["haskell"],
121 initializationOptions: getHLSConfig(),
123 lspClient = new LanguageClient(
124 "haskell-language-server",
129 sendNotification("Starting Haskell Language Server", "");
133function stopServer() {
135 sendNotification("Stopping Haskell Language Server", "");
140function getServerPath() {
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list