1// The module 'vscode' contains the VS Code extensibility API
2// Import the module and reference it with the alias vscode in your code below
3import * as vscode from 'vscode';
4import * as proc from 'child_process';
5import { Range } from 'vscode';
7// this method is called when your extension is activated
8// your extension is activated the very first time the command is executed
9const haskellLangId = 'haskell';
10export function activate(context: vscode.ExtensionContext) {
11 vscode.languages.registerDocumentRangeFormattingEditProvider(haskellLangId, {
12 provideDocumentRangeFormattingEdits(document, range, options, token) {
13 const showErrorMessage = (friendlyText: string, error: { stderr: { toString: () => void; }; }) => {
14 vscode.window.showWarningMessage(`${friendlyText}\n${error.stderr.toString()}`);
18 const cfg = vscode.workspace.getConfiguration("ormolu");
21 proc.execSync(cfg.executablePath + ' --help');
23 return showErrorMessage("Ormolu is not installed", e);
26 let command = cfg.executablePath;
28 command += ` --start-line ${range.start.line + 1} --end-line ${range.end.line + (range.end.character == 0 ? 0 : 1)}`
29 command += ` --stdin-input-file ${document.fileName}`
31 for (let [key, value] of Object.entries(cfg.extensions)) {
33 command += " -o -X" + key;
37 if (cfg.customArguments !== null) {
38 command += " " + cfg.customArguments;
41 if (cfg.tolerateCpp) {
49 if (cfg.checkIdempotency) {
53 const text = document.getText();
56 formattedText = proc.execSync(command, { input: text }).toString();
58 return showErrorMessage('Ormolu failed to format the code', e);
61 const fullDocumentRange =
63 (document.lineAt(0).range.start
64 , document.lineAt(document.lineCount - 1).range.end
67 return [vscode.TextEdit.replace(fullDocumentRange, formattedText)];
72// this method is called when your extension is deactivated
73export function deactivate() { }
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