on master help sign in
5 files changed+237−167
since splitsnapshots
unifiedsplit
CHANGELOG.md+46−4 README.md+12 logo.png package.json+161−155 src/extension.ts+18−8
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+12
@@ -21,3 +21,15 @@ Initial release of Ormolu
2121Added configurations.
2222
2323Changed error to warning.
24+
25+### 0.0.3
26+
27+Added logo.
28+
29+### 0.0.4
30+
31+Fixed bugs.
32+
33+### 0.0.5
34+
35+Fixed bugs.
logo.pngnew file

Binary file not shown.

package.json+161−155
@@ -1,157 +1,163 @@
11{
2− "name": "ormolu",
3− "displayName": "Ormolu",
4− "publisher": "ilyakooo0",
5− "description": "Haskell code formatter with ormolu",
6− "version": "0.0.2",
7− "repository": {
8− "type": "git",
9− "url": "https://github.com/ilyakooo0/vs-code-ormolu"
10− },
11− "engines": {
12− "vscode": "^1.39.0"
13− },
14− "categories": [
15− "Formatters"
16− ],
17− "main": "./out/extension.js",
18− "contributes": {
19− "languages": [
20− {
21− "id": "haskell",
22− "aliases": [
23− "Haskell"
24− ]
25− }
26− ],
27− "configuration": {
28− "title": "Ormolu",
29− "properties": {
30− "ormolu.extensions.AlternativeLayoutRule": {
31− "type": "boolean",
32− "default": false,
33− "description": "Enable the AlternativeLayoutRule extension."
34− },
35− "ormolu.extensions.AlternativeLayoutRuleTransitional": {
36− "type": "boolean",
37− "default": false,
38− "description": "Enable the AlternativeLayoutRuleTransitional extension."
39− },
40− "ormolu.extensions.Arrows": {
41− "type": "boolean",
42− "default": false,
43− "description": "Enable the Arrows extension."
44− },
45− "ormolu.extensions.BangPatterns": {
46− "type": "boolean",
47− "default": false,
48− "description": "Enable the BangPatterns extension."
49− },
50− "ormolu.extensions.Cpp": {
51− "type": "boolean",
52− "default": false,
53− "description": "Enable the Cpp extension."
54− },
55− "ormolu.extensions.MagicHash": {
56− "type": "boolean",
57− "default": false,
58− "description": "Enable the MagicHash extension."
59− },
60− "ormolu.extensions.MonadComprehensions": {
61− "type": "boolean",
62− "default": false,
63− "description": "Enable the MonadComprehensions extension."
64− },
65− "ormolu.extensions.PatternSynonyms": {
66− "type": "boolean",
67− "default": false,
68− "description": "Enable the PatternSynonyms extension."
69− },
70− "ormolu.extensions.RecursiveDo": {
71− "type": "boolean",
72− "default": false,
73− "description": "Enable the RecursiveDo extension."
74− },
75− "ormolu.extensions.StaticPointers": {
76− "type": "boolean",
77− "default": false,
78− "description": "Enable the StaticPointers extension."
79− },
80− "ormolu.extensions.TemplateHaskellQuotes": {
81− "type": "boolean",
82− "default": false,
83− "description": "Enable the TemplateHaskellQuotes extension."
84− },
85− "ormolu.extensions.TransformListComp": {
86− "type": "boolean",
87− "default": false,
88− "description": "Enable the TransformListComp extension."
89− },
90− "ormolu.extensions.TypeApplications": {
91− "type": "boolean",
92− "default": false,
93− "description": "Enable the TypeApplications extension."
94− },
95− "ormolu.extensions.UnboxedSums": {
96− "type": "boolean",
97− "default": false,
98− "description": "Enable the UnboxedSums extension."
99− },
100− "ormolu.extensions.UnboxedTuples": {
101− "type": "boolean",
102− "default": false,
103− "description": "Enable the UnboxedTuples extension."
104− },
105− "ormolu.extensions.UnicodeSyntax": {
106− "type": "boolean",
107− "default": false,
108− "description": "Enable the UnicodeSyntax extension."
109− },
110− "ormolu.tolerateCpp": {
111− "type": "boolean",
112− "default": false,
113− "description": "Do not fail if CPP pragma is present."
114− },
115− "ormolu.unsafe": {
116− "type": "boolean",
117− "default": false,
118− "description": "Run in \"unsafe\" mode. Do formatting faster but without automatic detection of defects."
119− },
120− "ormolu.checkIdempotency": {
121− "type": "boolean",
122− "default": false,
123− "description": "Fail if formatting is not idempotent."
124− },
125− "ormolu.customArguments": {
126− "type": [
127− "string",
128− "null"
129− ],
130− "default": null,
131− "description": "Custom arguments to pass to ormolu."
132− }
133− }
134− }
135− },
136− "activationEvents": [
137− "onLanguage:haskell"
138− ],
139− "scripts": {
140− "vscode:prepublish": "yarn run compile",
141− "compile": "tsc -p ./",
142− "watch": "tsc -watch -p ./",
143− "pretest": "yarn run compile",
144− "test": "node ./out/test/runTest.js"
145− },
146− "devDependencies": {
147− "@types/glob": "^7.1.1",
148− "@types/mocha": "^5.2.6",
149− "@types/node": "^10.12.21",
150− "@types/vscode": "^1.39.0",
151− "glob": "^7.1.4",
152− "mocha": "^6.1.4",
153− "typescript": "^3.3.1",
154− "tslint": "^5.12.1",
155− "vscode-test": "^1.2.0"
156− }
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",
19+ "contributes": {
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+ }
139+ }
140+ }
141+ },
142+ "activationEvents": [
143+ "onLanguage:haskell"
144+ ],
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+ }
157163}
src/extension.ts+18−8
@@ -2,7 +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 { isNull } from 'util';
5+import { Range } from 'vscode';
66
77// this method is called when your extension is activated
88// your extension is activated the very first time the command is executed
@@ -15,23 +15,26 @@ export function activate(context: vscode.ExtensionContext) {
1515 return [];
1616 };
1717
18+ const cfg = vscode.workspace.getConfiguration("ormolu");
19+
1820 try {
19− proc.execSync('ormolu --help');
21+ proc.execSync(cfg.executablePath + ' --help');
2022 } catch (e) {
2123 return showErrorMessage("Ormolu is not installed", e);
2224 }
2325
24− const cfg = vscode.workspace.getConfiguration("ormolu");
26+ let command = cfg.executablePath;
2527
26− let command = "ormolu";
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}`
2730
2831 for (let [key, value] of Object.entries(cfg.extensions)) {
2932 if (value) {
30− command += " -X" + key;
33+ command += " -o -X" + key;
3134 }
3235 }
3336
34− if (!isNull(cfg.customArguments)) {
37+ if (cfg.customArguments !== null) {
3538 command += " " + cfg.customArguments;
3639 }
3740
@@ -47,14 +50,21 @@ export function activate(context: vscode.ExtensionContext) {
4750 command += " -c";
4851 }
4952
50− const text = document.getText(range);
53+ const text = document.getText();
5154 let formattedText;
5255 try {
5356 formattedText = proc.execSync(command, { input: text }).toString();
5457 } catch (e) {
5558 return showErrorMessage('Ormolu failed to format the code', e);
5659 }
57− 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)];
5868 }
5969 });
6070}