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