on master help sign in
0.0.2
f4b1889iko
.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
README.md+9−1
@@ -1,5 +1,7 @@
1# Ormolu
1# Ormolu
2
2
3+Most ormolu options are exposed in configuration.
4+
3## Requirements
5## Requirements
4
6
5You have to have ormolu installed.
7You have to have ormolu installed.
@@ -10,6 +12,12 @@ Go to [github.com/tweag/ormolu](https://github.com/tweag/ormolu#building) for mo
10
12
11## Release Notes
13## Release Notes
12
14
13−### 1.0.0
15+### 0.0.1
14
16
15Initial release of Ormolu
17Initial release of Ormolu
18+
19+### 0.0.2
20+
21+Added configurations.
22+
23+Changed error to warning.
package.json+122−14
@@ -3,7 +3,7 @@
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.1",
6+ "version": "0.0.2",
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"
@@ -15,19 +15,127 @@
15 "Formatters"
15 "Formatters"
16 ],
16 ],
17 "main": "./out/extension.js",
17 "main": "./out/extension.js",
18− "contributes": {
18+ "contributes": {
19− "languages": [
19+ "languages": [
20− {
20+ {
21− "id": "haskell",
21+ "id": "haskell",
22− "aliases": [
22+ "aliases": [
23− "Haskell"
23+ "Haskell"
24− ]
24+ ]
25− }
25+ }
26− ]
26+ ],
27+ "configuration": {
28+ "title": "Ormolu",
29+ "properties": {
30+ "ormolu.extensions.AlternativeLayoutRule": {
31+ "type": "boolean",
32+ "default": false,
33+ "description": "Enable the AlternativeLayoutRule extension."
27− },
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+ },
28− "activationEvents": [
136+ "activationEvents": [
29− "onLanguage:haskell"
137+ "onLanguage:haskell"
30− ],
138+ ],
31 "scripts": {
139 "scripts": {
32 "vscode:prepublish": "yarn run compile",
140 "vscode:prepublish": "yarn run compile",
33 "compile": "tsc -p ./",
141 "compile": "tsc -p ./",
src/extension.ts+30−3
@@ -2,6 +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
6
6// this method is called when your extension is activated
7// this method is called when your extension is activated
7// 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
@@ -10,7 +11,7 @@ export function activate(context: vscode.ExtensionContext) {
10 vscode.languages.registerDocumentRangeFormattingEditProvider(haskellLangId, {
11 vscode.languages.registerDocumentRangeFormattingEditProvider(haskellLangId, {
11 provideDocumentRangeFormattingEdits(document, range, options, token) {
12 provideDocumentRangeFormattingEdits(document, range, options, token) {
12 const showErrorMessage = (friendlyText: string, error: { stderr: { toString: () => void; }; }) => {
13 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()}`);
14 return [];
15 return [];
15 };
16 };
16
17
@@ -20,10 +21,36 @@ export function activate(context: vscode.ExtensionContext) {
20 return showErrorMessage("Ormolu is not installed", e);
21 return showErrorMessage("Ormolu is not installed", e);
21 }
22 }
22
23
24+ const cfg = vscode.workspace.getConfiguration("ormolu");
25+
26+ let command = "ormolu";
27+
28+ for (let [key, value] of Object.entries(cfg.extensions)) {
29+ if (value) {
30+ command += " -X" + key;
31+ }
32+ }
33+
34+ if (!isNull(cfg.customArguments)) {
35+ command += " " + cfg.customArguments;
36+ }
37+
38+ if (cfg.tolerateCpp) {
39+ command += " -p";
40+ }
41+
42+ if (cfg.unsafe) {
43+ command += " -u";
44+ }
45+
46+ if (cfg.checkIdempotency) {
47+ command += " -c";
48+ }
49+
23 const text = document.getText(range);
50 const text = document.getText(range);
24 let formattedText;
51 let formattedText;
25 try {
52 try {
26− formattedText = proc.execSync('ormolu', {input: text}).toString();
53+ formattedText = proc.execSync(command, { input: text }).toString();
27 } catch (e) {
54 } catch (e) {
28 return showErrorMessage('Ormolu failed to format the code', e);
55 return showErrorMessage('Ormolu failed to format the code', e);
29 }
56 }
@@ -33,4 +60,4 @@ export function activate(context: vscode.ExtensionContext) {
33}
60}
34
61
35// this method is called when your extension is deactivated
62// this method is called when your extension is deactivated
36−export function deactivate() {}
63+export function deactivate() { }