on master help sign in
10 files changed+344−93
since splitsnapshots
unifiedsplit
.vscode/extensions.json+7 .vscode/launch.json+36 .vscode/settings.json+11 .vscode/tasks.json+20 .vscodeignore+10 CHANGELOG.md+46−4 README.md+16−46 logo.png package.json+155−37 src/extension.ts+43−6
.vscode/extensions.jsonnew file+7
@@ -0,0 +1,7 @@
1+{
2+ // See http://go.microsoft.com/fwlink/?LinkId=827846
3+ // for the documentation about the extensions.json format
4+ "recommendations": [
5+ "ms-vscode.vscode-typescript-tslint-plugin"
6+ ]
7+}
.vscode/launch.jsonnew file+36
@@ -0,0 +1,36 @@
1+// A launch configuration that compiles the extension and then opens it inside a new window
2+// Use IntelliSense to learn about possible attributes.
3+// Hover to view descriptions of existing attributes.
4+// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+{
6+ "version": "0.2.0",
7+ "configurations": [
8+ {
9+ "name": "Run Extension",
10+ "type": "extensionHost",
11+ "request": "launch",
12+ "runtimeExecutable": "${execPath}",
13+ "args": [
14+ "--extensionDevelopmentPath=${workspaceFolder}"
15+ ],
16+ "outFiles": [
17+ "${workspaceFolder}/out/**/*.js"
18+ ],
19+ "preLaunchTask": "npm: watch"
20+ },
21+ {
22+ "name": "Extension Tests",
23+ "type": "extensionHost",
24+ "request": "launch",
25+ "runtimeExecutable": "${execPath}",
26+ "args": [
27+ "--extensionDevelopmentPath=${workspaceFolder}",
28+ "--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
29+ ],
30+ "outFiles": [
31+ "${workspaceFolder}/out/test/**/*.js"
32+ ],
33+ "preLaunchTask": "npm: watch"
34+ }
35+ ]
36+}
.vscode/settings.jsonnew file+11
@@ -0,0 +1,11 @@
1+// Place your settings in this file to overwrite default and user settings.
2+{
3+ "files.exclude": {
4+ "out": false // set this to true to hide the "out" folder with the compiled JS files
5+ },
6+ "search.exclude": {
7+ "out": true // set this to false to include "out" folder in search results
8+ },
9+ // Turn off tsc task auto detection since we have the necessary tasks as npm scripts
10+ "typescript.tsc.autoDetect": "off"
11+}
.vscode/tasks.jsonnew file+20
@@ -0,0 +1,20 @@
1+// See https://go.microsoft.com/fwlink/?LinkId=733558
2+// for the documentation about the tasks.json format
3+{
4+ "version": "2.0.0",
5+ "tasks": [
6+ {
7+ "type": "npm",
8+ "script": "watch",
9+ "problemMatcher": "$tsc-watch",
10+ "isBackground": true,
11+ "presentation": {
12+ "reveal": "never"
13+ },
14+ "group": {
15+ "kind": "build",
16+ "isDefault": true
17+ }
18+ }
19+ ]
20+}
.vscodeignorenew file+10
@@ -0,0 +1,10 @@
1+.vscode/**
2+.vscode-test/**
3+out/test/**
4+src/**
5+.gitignore
6+vsc-extension-quickstart.md
7+**/tsconfig.json
8+**/tslint.json
9+**/*.map
10+**/*.ts
CHANGELOG.md+46−4
@@ -1,9 +1,51 @@
11# Change Log
22
3−All notable changes to the "ormolu" extension will be documented in this file.
3+### 0.0.12
44
5−Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
5+Fixed a bug where executable paths outside of `$PATH` would fail. (@lzszt)
66
7−## [Unreleased]
7+### 0.0.11
88
9−- Initial release
9+Added the ability to specify the path to the executable.
10+
11+### 0.0.10
12+
13+Fixed off-by-one range bug.
14+
15+### 0.0.9
16+
17+Fixed range values.
18+
19+### 0.0.8
20+
21+Fixed bug.
22+
23+### 0.0.7
24+
25+Fixed bug.
26+
27+### 0.0.6
28+
29+Added proper range support.
30+
31+### 0.0.5
32+
33+Fixed bugs.
34+
35+### 0.0.4
36+
37+Fixed bugs.
38+
39+### 0.0.3
40+
41+Added logo.
42+
43+### 0.0.2
44+
45+Added configurations.
46+
47+Changed error to warning.
48+
49+### 0.0.1
50+
51+Initial release of Ormolu
README.md+16−46
@@ -1,65 +1,35 @@
1−# ormolu README
1+# Ormolu
22
3−This is the README for your extension "ormolu". After writing up a brief description, we recommend including the following sections.
4−
5−## Features
6−
7−Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file.
8−
9−For example if there is an image subfolder under your extension project workspace:
10−
11−\!\[feature X\]\(images/feature-x.png\)
12−
13−> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow.
3+Most ormolu options are exposed in configuration.
144
155## Requirements
166
17−If you have any requirements or dependencies, add a section describing those and how to install and configure them.
18−
19−## Extension Settings
20−
21−Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.
7+You have to have ormolu installed.
228
23−For example:
9+Go to [github.com/tweag/ormolu](https://github.com/tweag/ormolu#building) for more info.
2410
25−This extension contributes the following settings:
26−
27−* `myExtension.enable`: enable/disable this extension
28−* `myExtension.thing`: set to `blah` to do something
29−
30−## Known Issues
31−
32−Calling out known issues can help limit users opening duplicate issues against your extension.
11+## Extension Settings
3312
3413## Release Notes
3514
36−Users appreciate release notes as you update your extension.
37−
38−### 1.0.0
39−
40−Initial release of ...
41−
42−### 1.0.1
15+### 0.0.1
4316
44−Fixed issue #.
17+Initial release of Ormolu
4518
46−### 1.1.0
19+### 0.0.2
4720
48−Added features X, Y, and Z.
21+Added configurations.
4922
50−-----------------------------------------------------------------------------------------------------------
23+Changed error to warning.
5124
52−## Working with Markdown
25+### 0.0.3
5326
54−**Note:** You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
27+Added logo.
5528
56−* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux)
57−* Toggle preview (`Shift+CMD+V` on macOS or `Shift+Ctrl+V` on Windows and Linux)
58−* Press `Ctrl+Space` (Windows, Linux) or `Cmd+Space` (macOS) to see a list of Markdown snippets
29+### 0.0.4
5930
60−### For more information
31+Fixed bugs.
6132
62−* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
63−* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)
33+### 0.0.5
6434
65−**Enjoy!**
35+Fixed bugs.
logo.pngnew file

Binary file not shown.

package.json+155−37
@@ -1,45 +1,163 @@
11{
2− "name": "ormolu",
3− "displayName": "Ormolu",
4− "publisher": "ilyakooo0",
5− "description": "Haskell code formatter with ormolu",
6− "version": "0.0.1",
7− "engines": {
8− "vscode": "^1.39.0"
9− },
10− "categories": [
11− "Formatters"
12− ],
13− "main": "./out/extension.js",
2+ "name": "ormolu",
3+ "displayName": "Ormolu",
4+ "publisher": "ilyakooo0",
5+ "description": "Haskell code formatter with ormolu",
6+ "version": "0.0.12",
7+ "repository": {
8+ "type": "git",
9+ "url": "https://github.com/ilyakooo0/vs-code-ormolu"
10+ },
11+ "icon": "logo.png",
12+ "engines": {
13+ "vscode": "^1.39.0"
14+ },
15+ "categories": [
16+ "Formatters"
17+ ],
18+ "main": "./out/extension.js",
1419 "contributes": {
15− "languages": [
16− {
17− "id": "haskell",
18− "aliases": [
19− "Haskell"
20− ]
20+ "languages": [{
21+ "id": "haskell",
22+ "aliases": [
23+ "Haskell"
24+ ]
25+ }],
26+ "configuration": {
27+ "title": "Ormolu",
28+ "properties": {
29+ "ormolu.extensions.AlternativeLayoutRule": {
30+ "type": "boolean",
31+ "default": false,
32+ "description": "Enable the AlternativeLayoutRule extension."
33+ },
34+ "ormolu.extensions.AlternativeLayoutRuleTransitional": {
35+ "type": "boolean",
36+ "default": false,
37+ "description": "Enable the AlternativeLayoutRuleTransitional extension."
38+ },
39+ "ormolu.extensions.Arrows": {
40+ "type": "boolean",
41+ "default": false,
42+ "description": "Enable the Arrows extension."
43+ },
44+ "ormolu.extensions.BangPatterns": {
45+ "type": "boolean",
46+ "default": false,
47+ "description": "Enable the BangPatterns extension."
48+ },
49+ "ormolu.extensions.Cpp": {
50+ "type": "boolean",
51+ "default": false,
52+ "description": "Enable the Cpp extension."
53+ },
54+ "ormolu.extensions.MagicHash": {
55+ "type": "boolean",
56+ "default": false,
57+ "description": "Enable the MagicHash extension."
58+ },
59+ "ormolu.extensions.MonadComprehensions": {
60+ "type": "boolean",
61+ "default": false,
62+ "description": "Enable the MonadComprehensions extension."
63+ },
64+ "ormolu.extensions.PatternSynonyms": {
65+ "type": "boolean",
66+ "default": false,
67+ "description": "Enable the PatternSynonyms extension."
68+ },
69+ "ormolu.extensions.RecursiveDo": {
70+ "type": "boolean",
71+ "default": false,
72+ "description": "Enable the RecursiveDo extension."
73+ },
74+ "ormolu.extensions.StaticPointers": {
75+ "type": "boolean",
76+ "default": false,
77+ "description": "Enable the StaticPointers extension."
78+ },
79+ "ormolu.extensions.TemplateHaskellQuotes": {
80+ "type": "boolean",
81+ "default": false,
82+ "description": "Enable the TemplateHaskellQuotes extension."
83+ },
84+ "ormolu.extensions.TransformListComp": {
85+ "type": "boolean",
86+ "default": false,
87+ "description": "Enable the TransformListComp extension."
88+ },
89+ "ormolu.extensions.TypeApplications": {
90+ "type": "boolean",
91+ "default": false,
92+ "description": "Enable the TypeApplications extension."
93+ },
94+ "ormolu.extensions.UnboxedSums": {
95+ "type": "boolean",
96+ "default": false,
97+ "description": "Enable the UnboxedSums extension."
98+ },
99+ "ormolu.extensions.UnboxedTuples": {
100+ "type": "boolean",
101+ "default": false,
102+ "description": "Enable the UnboxedTuples extension."
103+ },
104+ "ormolu.extensions.UnicodeSyntax": {
105+ "type": "boolean",
106+ "default": false,
107+ "description": "Enable the UnicodeSyntax extension."
108+ },
109+ "ormolu.tolerateCpp": {
110+ "type": "boolean",
111+ "default": false,
112+ "description": "Do not fail if CPP pragma is present."
113+ },
114+ "ormolu.unsafe": {
115+ "type": "boolean",
116+ "default": false,
117+ "description": "Run in \"unsafe\" mode. Do formatting faster but without automatic detection of defects."
118+ },
119+ "ormolu.checkIdempotency": {
120+ "type": "boolean",
121+ "default": false,
122+ "description": "Fail if formatting is not idempotent."
123+ },
124+ "ormolu.customArguments": {
125+ "type": [
126+ "string",
127+ "null"
128+ ],
129+ "default": null,
130+ "description": "Custom arguments to pass to ormolu."
131+ },
132+ "ormolu.executablePath": {
133+ "type": [
134+ "string"
135+ ],
136+ "default": "ormolu",
137+ "description": "The path to the ormolu executable to use."
138+ }
21139 }
22− ]
140+ }
23141 },
24142 "activationEvents": [
25143 "onLanguage:haskell"
26144 ],
27− "scripts": {
28− "vscode:prepublish": "yarn run compile",
29− "compile": "tsc -p ./",
30− "watch": "tsc -watch -p ./",
31− "pretest": "yarn run compile",
32− "test": "node ./out/test/runTest.js"
33− },
34− "devDependencies": {
35− "@types/glob": "^7.1.1",
36− "@types/mocha": "^5.2.6",
37− "@types/node": "^10.12.21",
38− "@types/vscode": "^1.39.0",
39− "glob": "^7.1.4",
40− "mocha": "^6.1.4",
41− "typescript": "^3.3.1",
42− "tslint": "^5.12.1",
43− "vscode-test": "^1.2.0"
44− }
145+ "scripts": {
146+ "vscode:prepublish": "yarn run compile",
147+ "compile": "tsc -p ./",
148+ "watch": "tsc -watch -p ./",
149+ "pretest": "yarn run compile",
150+ "test": "node ./out/test/runTest.js"
151+ },
152+ "devDependencies": {
153+ "@types/glob": "^7.1.1",
154+ "@types/mocha": "^5.2.6",
155+ "@types/node": "^10.12.21",
156+ "@types/vscode": "^1.39.0",
157+ "glob": "^7.1.4",
158+ "mocha": "^6.1.4",
159+ "typescript": "^3.3.1",
160+ "tslint": "^5.12.1",
161+ "vscode-test": "^1.2.0"
162+ }
45163}
src/extension.ts+43−6
@@ -2,6 +2,7 @@
22// Import the module and reference it with the alias vscode in your code below
33import * as vscode from 'vscode';
44import * as proc from 'child_process';
5+import { Range } from 'vscode';
56
67// this method is called when your extension is activated
78// your extension is activated the very first time the command is executed
@@ -10,27 +11,63 @@ export function activate(context: vscode.ExtensionContext) {
1011 vscode.languages.registerDocumentRangeFormattingEditProvider(haskellLangId, {
1112 provideDocumentRangeFormattingEdits(document, range, options, token) {
1213 const showErrorMessage = (friendlyText: string, error: { stderr: { toString: () => void; }; }) => {
13− vscode.window.showErrorMessage(`${friendlyText}\n${error.stderr.toString()}`);
14+ vscode.window.showWarningMessage(`${friendlyText}\n${error.stderr.toString()}`);
1415 return [];
1516 };
1617
18+ const cfg = vscode.workspace.getConfiguration("ormolu");
19+
1720 try {
18− proc.execSync('ormolu --help');
21+ proc.execSync(cfg.executablePath + ' --help');
1922 } catch (e) {
2023 return showErrorMessage("Ormolu is not installed", e);
2124 }
2225
23− const text = document.getText(range);
26+ let command = cfg.executablePath;
27+
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}`
30+
31+ for (let [key, value] of Object.entries(cfg.extensions)) {
32+ if (value) {
33+ command += " -o -X" + key;
34+ }
35+ }
36+
37+ if (cfg.customArguments !== null) {
38+ command += " " + cfg.customArguments;
39+ }
40+
41+ if (cfg.tolerateCpp) {
42+ command += " -p";
43+ }
44+
45+ if (cfg.unsafe) {
46+ command += " -u";
47+ }
48+
49+ if (cfg.checkIdempotency) {
50+ command += " -c";
51+ }
52+
53+ const text = document.getText();
2454 let formattedText;
2555 try {
26− formattedText = proc.execSync('ormolu', {input: text}).toString();
56+ formattedText = proc.execSync(command, { input: text }).toString();
2757 } catch (e) {
2858 return showErrorMessage('Ormolu failed to format the code', e);
2959 }
30− return [vscode.TextEdit.replace(range, formattedText)];
60+
61+ const fullDocumentRange =
62+ new Range
63+ (document.lineAt(0).range.start
64+ , document.lineAt(document.lineCount - 1).range.end
65+ );
66+
67+ return [vscode.TextEdit.replace(fullDocumentRange, formattedText)];
3168 }
3269 });
3370}
3471
3572// this method is called when your extension is deactivated
36−export function deactivate() {}
73+export function deactivate() { }