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