Skip to content

Commit fa52202

Browse files
committed
Add .editorconfig and format files
1 parent ea3c766 commit fa52202

File tree

6 files changed

+442
-380
lines changed

6 files changed

+442
-380
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_size = 2
5+
indent_style = space
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

src/extension.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as vscode from 'vscode';
1+
import * as vscode from "vscode";
22

3-
import ValeServerProvider from './features/vsProvider';
3+
import ValeServerProvider from "./features/vsProvider";
44

55
export function activate(context: vscode.ExtensionContext) {
6-
let linter = new ValeServerProvider();
7-
linter.activate(context.subscriptions);
6+
let linter = new ValeServerProvider();
7+
linter.activate(context.subscriptions);
88
}

src/features/vsCommands.ts

Lines changed: 104 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,148 @@
1-
import * as vscode from 'vscode';
1+
import * as vscode from "vscode";
22

3-
import * as path from 'path';
4-
import * as request from 'request-promise-native';
3+
import * as path from "path";
4+
import * as request from "request-promise-native";
55

66
/**
77
* An Alert From Vale.
88
*/
99
interface IValeConfigJSON {
10-
readonly Project: string;
11-
readonly StylesPath: string;
10+
readonly Project: string;
11+
readonly StylesPath: string;
1212
}
1313

1414
export default function InitCommands(subscriptions: vscode.Disposable[]) {
15-
subscriptions.push(
16-
vscode.commands.registerCommand('vale.addToAccept', addToAccept),
17-
vscode.commands.registerCommand('vale.addToReject', addToReject),
15+
subscriptions.push(
16+
vscode.commands.registerCommand("vale.addToAccept", addToAccept),
17+
vscode.commands.registerCommand("vale.addToReject", addToReject),
1818

19-
vscode.commands.registerCommand('vale.openAccept', openAccept),
20-
vscode.commands.registerCommand('vale.openReject', openReject)
21-
);
19+
vscode.commands.registerCommand("vale.openAccept", openAccept),
20+
vscode.commands.registerCommand("vale.openReject", openReject)
21+
);
2222
}
2323

2424
const addToAccept = async () => {
25-
await addToVocab("accept");
25+
await addToVocab("accept");
2626
};
2727
const addToReject = async () => {
28-
await addToVocab("reject");
28+
await addToVocab("reject");
2929
};
3030

3131
const openAccept = async () => {
32-
await openVocabFile("accept");
32+
await openVocabFile("accept");
3333
};
3434
const openReject = async () => {
35-
await openVocabFile("reject");
35+
await openVocabFile("reject");
3636
};
3737

3838
/**
3939
* Get the user's active Vale Server configuration.
4040
*/
4141
const getConfig = async (server: string): Promise<IValeConfigJSON> => {
42-
let config: IValeConfigJSON = {} as IValeConfigJSON;
42+
let config: IValeConfigJSON = {} as IValeConfigJSON;
4343

44-
await request.get({ uri: server + '/config', json: true })
45-
.catch((error) => {
46-
throw new Error(`Vale Server could not connect: ${error}.`);
47-
})
48-
.then((body) => {
49-
config = body;
50-
});
44+
await request
45+
.get({ uri: server + "/config", json: true })
46+
.catch((error) => {
47+
throw new Error(`Vale Server could not connect: ${error}.`);
48+
})
49+
.then((body) => {
50+
config = body;
51+
});
5152

52-
return config;
53+
return config;
5354
};
5455

5556
const openVocabFile = async (name: string) => {
56-
const configuration = vscode.workspace.getConfiguration();
57-
const server: string = configuration.get(
58-
'vale.server.serverURL',
59-
'http://localhost:7777'
60-
);
61-
const config: IValeConfigJSON = await getConfig(server);
62-
63-
const src = path.join(
64-
config.StylesPath,
65-
'Vocab',
66-
config.Project,
67-
name + '.txt');
68-
vscode.workspace.openTextDocument(src).then(
69-
doc => vscode.window.showTextDocument(doc)
70-
);
57+
const configuration = vscode.workspace.getConfiguration();
58+
const server: string = configuration.get(
59+
"vale.server.serverURL",
60+
"http://localhost:7777"
61+
);
62+
const config: IValeConfigJSON = await getConfig(server);
63+
64+
const src = path.join(
65+
config.StylesPath,
66+
"Vocab",
67+
config.Project,
68+
name + ".txt"
69+
);
70+
vscode.workspace
71+
.openTextDocument(src)
72+
.then((doc) => vscode.window.showTextDocument(doc));
7173
};
7274

7375
/**
7476
* Add the currently-selected word to the user's active Vocab.
7577
*/
7678
const addToVocab = async (filename: string) => {
77-
const editor = vscode.window.activeTextEditor;
78-
if (!editor) {
79-
return;
80-
}
81-
82-
const configuration = vscode.workspace.getConfiguration();
83-
const server: string = configuration.get(
84-
'vale.server.serverURL',
85-
'http://localhost:7777'
86-
);
87-
const config: IValeConfigJSON = await getConfig(server);
88-
89-
const word: string = editor.document.getText(editor.selection);
90-
const name: string = config.Project;
91-
const styles: string = config.StylesPath;
92-
93-
await request.get({
94-
uri: server + '/vocab',
95-
qs: {
96-
name: name,
97-
file: filename
98-
},
99-
json: true
79+
const editor = vscode.window.activeTextEditor;
80+
if (!editor) {
81+
return;
82+
}
83+
84+
const configuration = vscode.workspace.getConfiguration();
85+
const server: string = configuration.get(
86+
"vale.server.serverURL",
87+
"http://localhost:7777"
88+
);
89+
const config: IValeConfigJSON = await getConfig(server);
90+
91+
const word: string = editor.document.getText(editor.selection);
92+
const name: string = config.Project;
93+
const styles: string = config.StylesPath;
94+
95+
await request
96+
.get({
97+
uri: server + "/vocab",
98+
qs: {
99+
name: name,
100+
file: filename,
101+
},
102+
json: true,
100103
})
101104
.catch((error) => {
102-
throw new Error(`Vale Server could not connect: ${error}.`);
105+
throw new Error(`Vale Server could not connect: ${error}.`);
103106
})
104107
.then((contents: Array<string>) => {
105-
contents.push(word);
106-
107-
// TODO: Do we need to (shoud we?) sort ourselves?
108-
let body = [...new Set(contents)].sort((a, b) => {
109-
if (a.toLowerCase() > b.toLowerCase()) {
110-
return 1;
111-
} else if (a.toLowerCase() < b.toLowerCase()) {
112-
return -1;
113-
}
114-
return 0;
115-
});
116-
117-
request.post({
118-
uri: server + '/update',
119-
qs: {
120-
path: name + '.' + filename,
121-
text: body.join('\n')
122-
},
123-
json: true
124-
}).catch((error) => {
125-
throw new Error(`Vale Server could not connect: ${error}.`);
126-
}).then(() => {
127-
const src = path.join(styles, 'Vocab', name, filename + '.txt');
128-
vscode.window.showInformationMessage(
129-
`Successfully added '${word}' to '${name}' vocab.`,
130-
...['View File']).then(selection => {
131-
if (selection === 'View File') {
132-
vscode.workspace.openTextDocument(src).then(
133-
doc => vscode.window.showTextDocument(doc)
134-
);
135-
}
136-
});
108+
contents.push(word);
109+
110+
// TODO: Do we need to (shoud we?) sort ourselves?
111+
let body = [...new Set(contents)].sort((a, b) => {
112+
if (a.toLowerCase() > b.toLowerCase()) {
113+
return 1;
114+
} else if (a.toLowerCase() < b.toLowerCase()) {
115+
return -1;
116+
}
117+
return 0;
118+
});
119+
120+
request
121+
.post({
122+
uri: server + "/update",
123+
qs: {
124+
path: name + "." + filename,
125+
text: body.join("\n"),
126+
},
127+
json: true,
128+
})
129+
.catch((error) => {
130+
throw new Error(`Vale Server could not connect: ${error}.`);
131+
})
132+
.then(() => {
133+
const src = path.join(styles, "Vocab", name, filename + ".txt");
134+
vscode.window
135+
.showInformationMessage(
136+
`Successfully added '${word}' to '${name}' vocab.`,
137+
...["View File"]
138+
)
139+
.then((selection) => {
140+
if (selection === "View File") {
141+
vscode.workspace
142+
.openTextDocument(src)
143+
.then((doc) => vscode.window.showTextDocument(doc));
144+
}
145+
});
137146
});
138147
});
139148
};

0 commit comments

Comments
 (0)