on master help sign in
Initial commit
commitceb9a6f463352b93b8eecbec0fa15579bfc905ae authoriko <ilyakooo0@gmail.com> dateTue 15 Oct 2019, 13:39 (7 years ago) parent70d8689
11 files changed+309
.gitignore+2 CHANGELOG.md+9 README.md+65 package.json+44 src/extension.ts+36 src/test/runTest.ts+23 src/test/suite/extension.test.ts+15 src/test/suite/index.ts+37 tsconfig.json+21 tslint.json+15 vsc-extension-quickstart.md+42
.gitignorenew file+2
@@ -0,0 +1,2 @@
1+node_modules
2+out
CHANGELOG.mdnew file+9
@@ -0,0 +1,9 @@
1+# Change Log
2+
3+All notable changes to the "ormolu" extension will be documented in this file.
4+
5+Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
6+
7+## [Unreleased]
8+
9+- Initial release
README.mdnew file+65
@@ -0,0 +1,65 @@
1+# ormolu README
2+
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.
14+
15+## Requirements
16+
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.
22+
23+For example:
24+
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.
33+
34+## Release Notes
35+
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
43+
44+Fixed issue #.
45+
46+### 1.1.0
47+
48+Added features X, Y, and Z.
49+
50+-----------------------------------------------------------------------------------------------------------
51+
52+## Working with Markdown
53+
54+**Note:** You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
55+
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
59+
60+### For more information
61+
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/)
64+
65+**Enjoy!**
package.jsonnew file+44
@@ -0,0 +1,44 @@
1+{
2+ "name": "ormolu",
3+ "displayName": "Ormolu",
4+ "description": "Haskell code formatter with ormolu",
5+ "version": "0.0.1",
6+ "engines": {
7+ "vscode": "^1.39.0"
8+ },
9+ "categories": [
10+ "Formatters"
11+ ],
12+ "main": "./out/extension.js",
13+ "contributes": {
14+ "languages": [
15+ {
16+ "id": "haskell",
17+ "aliases": [
18+ "Haskell"
19+ ]
20+ }
21+ ]
22+ },
23+ "activationEvents": [
24+ "onLanguage:haskell"
25+ ],
26+ "scripts": {
27+ "vscode:prepublish": "yarn run compile",
28+ "compile": "tsc -p ./",
29+ "watch": "tsc -watch -p ./",
30+ "pretest": "yarn run compile",
31+ "test": "node ./out/test/runTest.js"
32+ },
33+ "devDependencies": {
34+ "@types/glob": "^7.1.1",
35+ "@types/mocha": "^5.2.6",
36+ "@types/node": "^10.12.21",
37+ "@types/vscode": "^1.39.0",
38+ "glob": "^7.1.4",
39+ "mocha": "^6.1.4",
40+ "typescript": "^3.3.1",
41+ "tslint": "^5.12.1",
42+ "vscode-test": "^1.2.0"
43+ }
44+}
src/extension.tsnew file+36
@@ -0,0 +1,36 @@
1+// The module 'vscode' contains the VS Code extensibility API
2+// Import the module and reference it with the alias vscode in your code below
3+import * as vscode from 'vscode';
4+import * as proc from 'child_process';
5+
6+// this method is called when your extension is activated
7+// your extension is activated the very first time the command is executed
8+const haskellLangId = 'haskell';
9+export function activate(context: vscode.ExtensionContext) {
10+ vscode.languages.registerDocumentRangeFormattingEditProvider(haskellLangId, {
11+ provideDocumentRangeFormattingEdits(document, range, options, token) {
12+ const showErrorMessage = (friendlyText: string, error: { stderr: { toString: () => void; }; }) => {
13+ vscode.window.showErrorMessage(`${friendlyText}\n${error.stderr.toString()}`);
14+ return [];
15+ };
16+
17+ try {
18+ proc.execSync('ormolu --help');
19+ } catch (e) {
20+ return showErrorMessage("Ormolu is not installed", e);
21+ }
22+
23+ const text = document.getText(range);
24+ let formattedText;
25+ try {
26+ formattedText = proc.execSync('ormolu', {input: text}).toString();
27+ } catch (e) {
28+ return showErrorMessage('Ormolu failed to format the code', e);
29+ }
30+ return [vscode.TextEdit.replace(range, formattedText)];
31+ }
32+ });
33+}
34+
35+// this method is called when your extension is deactivated
36+export function deactivate() {}
src/test/runTest.tsnew file+23
@@ -0,0 +1,23 @@
1+import * as path from 'path';
2+
3+import { runTests } from 'vscode-test';
4+
5+async function main() {
6+ try {
7+ // The folder containing the Extension Manifest package.json
8+ // Passed to `--extensionDevelopmentPath`
9+ const extensionDevelopmentPath = path.resolve(__dirname, '../../');
10+
11+ // The path to test runner
12+ // Passed to --extensionTestsPath
13+ const extensionTestsPath = path.resolve(__dirname, './suite/index');
14+
15+ // Download VS Code, unzip it and run the integration test
16+ await runTests({ extensionDevelopmentPath, extensionTestsPath });
17+ } catch (err) {
18+ console.error('Failed to run tests');
19+ process.exit(1);
20+ }
21+}
22+
23+main();
src/test/suite/extension.test.tsnew file+15
@@ -0,0 +1,15 @@
1+import * as assert from 'assert';
2+
3+// You can import and use all API from the 'vscode' module
4+// as well as import your extension to test it
5+import * as vscode from 'vscode';
6+// import * as myExtension from '../extension';
7+
8+suite('Extension Test Suite', () => {
9+ vscode.window.showInformationMessage('Start all tests.');
10+
11+ test('Sample test', () => {
12+ assert.equal(-1, [1, 2, 3].indexOf(5));
13+ assert.equal(-1, [1, 2, 3].indexOf(0));
14+ });
15+});
src/test/suite/index.tsnew file+37
@@ -0,0 +1,37 @@
1+import * as path from 'path';
2+import * as Mocha from 'mocha';
3+import * as glob from 'glob';
4+
5+export function run(): Promise<void> {
6+ // Create the mocha test
7+ const mocha = new Mocha({
8+ ui: 'tdd',
9+ });
10+ mocha.useColors(true);
11+
12+ const testsRoot = path.resolve(__dirname, '..');
13+
14+ return new Promise((c, e) => {
15+ glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
16+ if (err) {
17+ return e(err);
18+ }
19+
20+ // Add files to the test suite
21+ files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
22+
23+ try {
24+ // Run the mocha test
25+ mocha.run(failures => {
26+ if (failures > 0) {
27+ e(new Error(`${failures} tests failed.`));
28+ } else {
29+ c();
30+ }
31+ });
32+ } catch (err) {
33+ e(err);
34+ }
35+ });
36+ });
37+}
tsconfig.jsonnew file+21
@@ -0,0 +1,21 @@
1+{
2+ "compilerOptions": {
3+ "module": "commonjs",
4+ "target": "es6",
5+ "outDir": "out",
6+ "lib": [
7+ "es6"
8+ ],
9+ "sourceMap": true,
10+ "rootDir": "src",
11+ "strict": true /* enable all strict type-checking options */
12+ /* Additional Checks */
13+ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
14+ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
15+ // "noUnusedParameters": true, /* Report errors on unused parameters. */
16+ },
17+ "exclude": [
18+ "node_modules",
19+ ".vscode-test"
20+ ]
21+}
tslint.jsonnew file+15
@@ -0,0 +1,15 @@
1+{
2+ "rules": {
3+ "no-string-throw": true,
4+ "no-unused-expression": true,
5+ "no-duplicate-variable": true,
6+ "curly": true,
7+ "class-name": true,
8+ "semicolon": [
9+ true,
10+ "always"
11+ ],
12+ "triple-equals": true
13+ },
14+ "defaultSeverity": "warning"
15+}
vsc-extension-quickstart.mdnew file+42
@@ -0,0 +1,42 @@
1+# Welcome to your VS Code Extension
2+
3+## What's in the folder
4+
5+* This folder contains all of the files necessary for your extension.
6+* `package.json` - this is the manifest file in which you declare your extension and command.
7+ * The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin.
8+* `src/extension.ts` - this is the main file where you will provide the implementation of your command.
9+ * The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`.
10+ * We pass the function containing the implementation of the command as the second parameter to `registerCommand`.
11+
12+## Get up and running straight away
13+
14+* Press `F5` to open a new window with your extension loaded.
15+* Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`.
16+* Set breakpoints in your code inside `src/extension.ts` to debug your extension.
17+* Find output from your extension in the debug console.
18+
19+## Make changes
20+
21+* You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`.
22+* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes.
23+
24+
25+## Explore the API
26+
27+* You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`.
28+
29+## Run tests
30+
31+* Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Extension Tests`.
32+* Press `F5` to run the tests in a new window with your extension loaded.
33+* See the output of the test result in the debug console.
34+* Make changes to `src/test/suite/extension.test.ts` or create new test files inside the `test/suite` folder.
35+ * The provided test runner will only consider files matching the name pattern `**.test.ts`.
36+ * You can create folders inside the `test` folder to structure your tests any way you want.
37+
38+## Go further
39+
40+ * Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension).
41+ * [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VSCode extension marketplace.
42+ * Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration).