-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathextension.ts
137 lines (114 loc) · 4.88 KB
/
extension.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import semver = require('semver');
import { commands, DocumentFilter, ExtensionContext, languages, workspace, version, extensions } from 'vscode';
import { batchExecuteFile } from './batch';
import { LeanCompletionItemProvider } from './completion';
import { LeanDefinitionProvider } from './definition';
import { LeanDiagnosticsProvider } from './diagnostics';
import { DocViewProvider } from './docview';
import { LeanHoles } from './holes';
import { TacticSuggestions } from './tacticsuggestions';
import { LeanHoverProvider } from './hover';
import { InfoProvider } from './infoview';
import { AbbreviationFeature } from './abbreviation';
import { LeanpkgService } from './leanpkg';
import { RoiManager } from './roi';
import { LeanWorkspaceSymbolProvider } from './search';
import { Server } from './server';
import { LeanStatusBarItem } from './statusbar';
import { LeanDocumentSymbolProvider } from './symbol';
import { LeanSyncService } from './sync';
import { LeanTaskGutter, LeanTaskMessages } from './taskgutter';
import { StaticServer } from './staticserver';
import { LibraryNoteLinkProvider } from './librarynote';
async function checkLean3(): Promise<boolean> {
const lean4 = extensions.getExtension('leanprover.lean4');
if (!lean4) {
return true;
}
return !(await lean4.activate()).isLean4Project;
}
// Seeing .olean files in the source tree is annoying, we should
// just globally hide them.
async function configExcludeOLean() {
const files = workspace.getConfiguration('files');
const exclude = files.get('exclude');
exclude['**/*.olean'] = true;
await files.update('exclude', exclude, true);
}
const LEAN_MODE: DocumentFilter = {
language: 'lean',
// The doc view uses the untitled scheme.
// scheme: 'file',
};
export async function activate(context: ExtensionContext): Promise<void> {
const isLean3 = await checkLean3();
if (!isLean3) {
return;
}
void configExcludeOLean();
const server = new Server();
context.subscriptions.push(server);
const roiManager = new RoiManager(server, LEAN_MODE);
context.subscriptions.push(roiManager);
// The sync service starts automatically starts
// the server when it sees a *.lean file.
context.subscriptions.push(new LeanSyncService(server, LEAN_MODE));
// Setup the commands.
context.subscriptions.push(
commands.registerCommand('lean.restartServer', () => server.restart()),
commands.registerTextEditorCommand('lean.batchExecute',
(editor, edit, args) => { batchExecuteFile(server, editor, edit, args); }),
);
context.subscriptions.push(new LeanDiagnosticsProvider(server));
// Task messages.
context.subscriptions.push(
new LeanTaskGutter(server, context),
new LeanTaskMessages(server),
);
// Register the support for hovering.
context.subscriptions.push(
languages.registerHoverProvider(LEAN_MODE,
new LeanHoverProvider(server)));
// Register support for completion.
context.subscriptions.push(
languages.registerCompletionItemProvider(
LEAN_MODE, new LeanCompletionItemProvider(server), '.'));
// Register support for unicode input.
context.subscriptions.push(new AbbreviationFeature());
// Register support for definition support.
context.subscriptions.push(
languages.registerDefinitionProvider(
LEAN_MODE, new LeanDefinitionProvider(server)));
// Search
context.subscriptions.push(
languages.registerWorkspaceSymbolProvider(
new LeanWorkspaceSymbolProvider(server)));
// Symbols
context.subscriptions.push(
languages.registerDocumentSymbolProvider(
LEAN_MODE, new LeanDocumentSymbolProvider(server)));
// Holes
context.subscriptions.push(new LeanHoles(server, LEAN_MODE));
// Add item to the status bar.
context.subscriptions.push(new LeanStatusBarItem(server, roiManager));
let staticServer = null;
function waitStaticServer() {
// Add info view: listing either the current goal state or a list of all error messages
const infoView = new InfoProvider(server, LEAN_MODE, context, staticServer);
context.subscriptions.push(infoView);
context.subscriptions.push(new DocViewProvider(staticServer));
// Tactic suggestions
context.subscriptions.push(new TacticSuggestions(server, infoView, LEAN_MODE));
}
// https://github.com/microsoft/vscode/issues/89038 fixed in 1.47
if (semver.gte(version, '1.47.0')) {
waitStaticServer();
} else {
staticServer = new StaticServer(context);
context.subscriptions.push(staticServer);
staticServer.server.on('listening', waitStaticServer);
}
context.subscriptions.push(new LeanpkgService(server));
context.subscriptions.push(languages.registerDocumentLinkProvider(LEAN_MODE,
new LibraryNoteLinkProvider()));
}