-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathextension.ts
257 lines (211 loc) · 7.26 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
import { GitListener } from './listeners/general/GitListener';
import * as vscode from 'vscode';
import { COMMAND_NAME, CONTEXT, EXTENSION_NAME } from './constants';
import { MarkdownFoldingProvider } from './providers/MarkdownFoldingProvider';
import { PanelProvider } from './panelWebView/PanelProvider';
import {
DashboardSettings,
debounceCallback,
Logger,
parseWinPath,
Settings as SettingsHelper
} from './helpers';
import ContentProvider from './providers/ContentProvider';
import { PagesListener } from './listeners/dashboard';
import { ModeSwitch } from './services/ModeSwitch';
import { PagesParser } from './services/PagesParser';
import { ContentType, Extension } from './helpers';
import * as l10n from '@vscode/l10n';
import {
Backers,
Diagnostics,
Wysiwyg,
Content,
Cache,
Template,
Project,
Preview,
Folders,
Dashboard,
Article,
Settings,
StatusListener,
Chatbot,
Taxonomy
} from './commands';
import { join } from 'path';
import { Terminal } from './services';
import { i18n } from './commands/i18n';
import { UriHandler } from './providers/UriHandler';
let pageUpdateDebouncer: { (fnc: any, time: number): void };
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let editDebounce: { (fnc: any, time: number): void };
let collection: vscode.DiagnosticCollection;
export async function activate(context: vscode.ExtensionContext) {
const { subscriptions, extensionUri, extensionPath } = context;
const extension = Extension.getInstance(context);
Logger.info(`Activating ${EXTENSION_NAME} version ${Extension.getInstance().version}...`);
// Set development context
if (!Extension.getInstance().isProductionMode) {
vscode.commands.executeCommand('setContext', CONTEXT.isDevelopment, true);
}
// Sponsor check
Backers.init(context);
// Make sure the EN language file is loaded
if (!vscode.l10n.uri) {
l10n.config({
fsPath: vscode.Uri.file(join(parseWinPath(extensionPath), `/l10n/bundle.l10n.json`)).fsPath
});
} else {
l10n.config({
fsPath: vscode.l10n.uri.fsPath
});
}
// Make sure the terminal windows are closed
Terminal.closeLocalServerTerminal();
if (!extension.checkIfExtensionCanRun()) {
return undefined;
}
await SettingsHelper.init();
extension.migrateSettings();
SettingsHelper.checkToPromote();
// Start listening to the folders for content changes.
// This will make sure the dashboard is up to date
PagesListener.startWatchers();
collection = vscode.languages.createDiagnosticCollection('frontMatter');
// Pages dashboard
Dashboard.init();
Dashboard.registerCommands();
// Multilingual commands
i18n.register();
// Setting commands
Settings.registerCommands();
SettingsHelper.registerCommands();
if (!extension.getVersion().usedVersion) {
vscode.commands.executeCommand(COMMAND_NAME.dashboard);
}
// Register the explorer view
const explorerSidebar = PanelProvider.getInstance(extensionUri);
const PanelView = vscode.window.registerWebviewViewProvider(
PanelProvider.viewType,
explorerSidebar,
{
webviewOptions: {
retainContextWhenHidden: true
}
}
);
// Folding the front matter of markdown files
MarkdownFoldingProvider.register();
// Register the taxonomy commands
Taxonomy.registerCommands(subscriptions);
// Register all the article commands and listeners
Article.registerCommands(subscriptions);
Article.registerListeners(subscriptions);
// Template creation
Template.registerCommands();
// Content creation
ContentType.registerCommands();
Content.registerCommands();
Folders.registerCommands();
// Project commands
Project.registerCommands();
// Collapse all sections in the webview
const collapseAll = vscode.commands.registerCommand(COMMAND_NAME.collapseSections, () => {
PanelProvider.getInstance()?.collapseAll();
});
// Things to do when configuration changes
SettingsHelper.startListening();
// Create the status bar
const fmStatusBarItem = vscode.window.createStatusBarItem(
'fm-statusBarItem',
vscode.StatusBarAlignment.Right,
-100
);
fmStatusBarItem.command = COMMAND_NAME.dashboard;
fmStatusBarItem.text = `$(fm-logo) ${extension.getVersion().installedVersion}`;
fmStatusBarItem.tooltip = EXTENSION_NAME;
fmStatusBarItem.show();
// Register listeners that make sure the status bar updates
pageUpdateDebouncer = debounceCallback();
subscriptions.push(
vscode.window.onDidChangeActiveTextEditor(() =>
triggerPageUpdate(`onDidChangeActiveTextEditor`)
)
);
subscriptions.push(
vscode.window.onDidChangeTextEditorSelection((e) => {
if (e.kind === vscode.TextEditorSelectionChangeKind.Mouse) {
pageUpdateDebouncer(() => triggerPageUpdate(`onDidChangeTextEditorSelection`), 200);
}
})
);
subscriptions.push(
vscode.workspace.onDidChangeTextDocument((TextDocumentChangeEvent) => {
const filePath = TextDocumentChangeEvent.document.uri.fsPath;
if (filePath && !filePath.toLowerCase().startsWith(`extension-output`)) {
MarkdownFoldingProvider.triggerHighlighting();
pageUpdateDebouncer(() => triggerPageUpdate(`onDidChangeTextEditorSelection`), 200);
}
})
);
// Automatically run the command
triggerPageUpdate(`main`);
// Listener for file saves
subscriptions.push(PagesListener.saveFileWatcher());
// Webview for preview
Preview.init();
subscriptions.push(
vscode.commands.registerCommand(COMMAND_NAME.preview, () => Preview.open(extensionPath))
);
// Open docs
subscriptions.push(
vscode.commands.registerCommand(COMMAND_NAME.docs, () => {
vscode.commands.executeCommand(
`simpleBrowser.show`,
`https://${extension.isBetaVersion() ? `beta.` : ``}frontmatter.codes/docs`
);
})
);
// Chat to the bot
subscriptions.push(
vscode.commands.registerCommand(COMMAND_NAME.chatbot, () => Chatbot.open(extensionPath))
);
// Create the editor experience for bulk scripts
subscriptions.push(
vscode.workspace.registerTextDocumentContentProvider(
ContentProvider.scheme,
new ContentProvider()
)
);
// What you see, is what you get
Wysiwyg.registerCommands(subscriptions);
// Mode switching
ModeSwitch.register();
// Diagnostics
Diagnostics.registerCommands();
// Git
GitListener.init();
// Once everything is registered, the page parsing can start in the background
DashboardSettings.get();
PagesParser.start();
// Cache commands
Cache.registerCommands();
// Register the URI handler
UriHandler.register();
// Subscribe all commands
subscriptions.push(PanelView, collapseAll, fmStatusBarItem);
// eslint-disable-next-line no-console
console.log(`𝖥𝗋𝗈𝗇𝗍 𝖬𝖺𝗍𝗍𝖾𝗋 𝖢𝖬𝖲 𝖺𝖼𝗍𝗂𝗏𝖺𝗍𝖾𝖽! 𝖱𝖾𝖺𝖽𝗒 𝗍𝗈 𝗌𝗍𝖺𝗋𝗍 𝗐𝗋𝗂𝗍𝗂𝗇𝗀... 👩💻🧑💻👨💻`);
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
export function deactivate() {}
const triggerPageUpdate = (location: string) => {
Logger.verbose(`Trigger page update: ${location}`);
pageUpdateDebouncer(() => {
StatusListener.verify(collection);
}, 1000);
if (location === 'onDidChangeActiveTextEditor') {
PanelProvider.getInstance()?.updateCurrentFile();
}
};