-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathproto3Main.ts
121 lines (103 loc) · 5.14 KB
/
proto3Main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
'use strict';
import * as path from 'path';
import vscode = require('vscode');
import cp = require('child_process');
import { Proto3CompletionItemProvider } from './proto3Suggest';
import { Proto3LanguageDiagnosticProvider } from './proto3Diagnostic';
import { Proto3Compiler } from './proto3Compiler';
import { PROTO3_MODE } from './proto3Mode';
import { Proto3DefinitionProvider } from './proto3Definition';
import { Proto3Configuration } from './proto3Configuration';
import { Proto3DocumentSymbolProvider } from './proto3SymbolProvider';
import { Proto3RenameProvider } from './proto3Rename';
export function activate(ctx: vscode.ExtensionContext): void {
ctx.subscriptions.push(vscode.languages.registerCompletionItemProvider(PROTO3_MODE, new Proto3CompletionItemProvider(), '.', '\"'));
ctx.subscriptions.push(vscode.languages.registerDefinitionProvider(PROTO3_MODE, new Proto3DefinitionProvider()));
ctx.subscriptions.push(vscode.languages.registerRenameProvider(PROTO3_MODE, new Proto3RenameProvider()));
const diagnosticProvider = new Proto3LanguageDiagnosticProvider();
vscode.languages.registerDocumentSymbolProvider('proto3', new Proto3DocumentSymbolProvider())
vscode.workspace.onDidSaveTextDocument(event => {
if (event.languageId == 'proto3') {
const workspaceFolder = vscode.workspace.getWorkspaceFolder(event.uri);
const compiler = new Proto3Compiler(workspaceFolder);
diagnosticProvider.createDiagnostics(event, compiler);
if (Proto3Configuration.Instance(workspaceFolder).compileOnSave()) {
compiler.compileActiveProto();
}
}
});
ctx.subscriptions.push(vscode.commands.registerCommand('proto3.compile.one', () => {
const currentFile = vscode.window.activeTextEditor?.document;
const workspaceFolder = vscode.workspace.getWorkspaceFolder(currentFile.uri)
const compiler = new Proto3Compiler(workspaceFolder);
compiler.compileActiveProto();
}));
ctx.subscriptions.push(vscode.commands.registerCommand('proto3.compile.all', () => {
const currentFile = vscode.window.activeTextEditor?.document;
const workspaceFolder = vscode.workspace.getWorkspaceFolder(currentFile.uri)
const compiler = new Proto3Compiler(workspaceFolder);
compiler.compileAllProtos();
}));
//console.log('Congratulations, your extension "vscode-pb3" is now active!');
vscode.languages.setLanguageConfiguration(PROTO3_MODE.language, {
indentationRules: {
// ^(.*\*/)?\s*\}.*$
decreaseIndentPattern: /^(.*\*\/)?\s*\}.*$/,
// ^.*\{[^}'']*$
increaseIndentPattern: /^.*\{[^}'']*$/
},
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)(\.proto){0,1}/g,
comments: {
lineComment: '//',
blockComment: ['/*', '*/']
},
brackets: [
['{', '}'],
['[', ']'],
['(', ')'],
['<', '>'],
],
__electricCharacterSupport: {
brackets: [
{ tokenType: 'delimiter.curly.ts', open: '{', close: '}', isElectric: true },
{ tokenType: 'delimiter.square.ts', open: '[', close: ']', isElectric: true },
{ tokenType: 'delimiter.paren.ts', open: '(', close: ')', isElectric: true }
]
},
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '`', close: '`', notIn: ['string'] },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] }
]
}
});
vscode.languages.registerDocumentFormattingEditProvider('proto3', {
provideDocumentFormattingEdits(document: vscode.TextDocument): vscode.TextEdit[] {
let args = [];
let opts = { input: document.getText() };
// In order for clang-format to find the correct formatting file we need to have cwd set appropriately
switch (document.uri.scheme) {
case "untitled": // File has not yet been saved to disk use workspace path
opts['cwd'] = vscode.workspace.rootPath;
args.push(`--assume-filename=untitled.proto`);
break;
case "file": // File is on disk use it's directory
opts['cwd'] = path.dirname(document.uri.fsPath);
args.push(`--assume-filename=${document.uri.fsPath}`);
break;
}
let style = vscode.workspace.getConfiguration('clang-format', document).get<string>('style');
style = style && style.trim();
if (style) args.push(`-style=${style}`);
let stdout = cp.execFileSync('clang-format', args, opts);
return [new vscode.TextEdit(document.validateRange(new vscode.Range(0, 0, Infinity, Infinity)), stdout ? stdout.toString() : '')];
},
});
}
function deactivate() {
//
}