-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: handle extension registration efficiently
- Loading branch information
Showing
3 changed files
with
13 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { commands, Disposable, window } from 'vscode'; | ||
|
||
export const ACTIVATION_COMMAND: Disposable = commands.registerCommand('scss-formatter.activate', () => { | ||
window.showInformationMessage('SCSS Formatter Activated'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,18 @@ | ||
'use strict'; | ||
|
||
import { | ||
commands, Disposable, ExtensionContext, | ||
languages, window, workspace | ||
} from 'vscode'; | ||
import { ExtensionContext, languages } from 'vscode'; | ||
|
||
import { ACTIVATION_COMMAND } from './commandManager'; | ||
import { registerErrorHandlerDisposables, setupErrorHandler } from './errorHandler'; | ||
import { SCSSFormatter } from './ScssFormatProvider'; | ||
import { SCSSFormatter } from './scssFormatterProvider'; | ||
import { languageSelector } from './utils'; | ||
|
||
let formatterHandler: undefined | Disposable; | ||
|
||
// dispose formatter | ||
function disposeHandlers() { | ||
if (formatterHandler) { | ||
formatterHandler.dispose(); | ||
} | ||
formatterHandler = undefined; | ||
} | ||
|
||
// register formatter | ||
function registerFormatter() { | ||
disposeHandlers(); | ||
const scssFormatter = new SCSSFormatter(); | ||
formatterHandler = languages.registerDocumentFormattingEditProvider( | ||
languageSelector, scssFormatter | ||
); | ||
} | ||
|
||
// method is called when extension is activated | ||
export function activate(context: ExtensionContext) { | ||
registerFormatter(); | ||
|
||
const disposable = commands.registerCommand('scss-formatter.activate', () => { | ||
window.showInformationMessage('SCSS Formatter Activated'); | ||
}); | ||
const scssFormatter = new SCSSFormatter(); | ||
|
||
context.subscriptions.push( | ||
workspace.onDidChangeWorkspaceFolders(registerFormatter), | ||
{ dispose: disposeHandlers }, | ||
setupErrorHandler(), | ||
disposable, | ||
...registerErrorHandlerDisposables() | ||
); | ||
context.subscriptions.push(languages.registerDocumentFormattingEditProvider(languageSelector, scssFormatter)); | ||
context.subscriptions.push(ACTIVATION_COMMAND); | ||
context.subscriptions.push(setupErrorHandler()); | ||
context.subscriptions.push(...registerErrorHandlerDisposables()); | ||
} | ||
|
||
// method is called when extension is deactivated | ||
export function deactivate() { } // tslint:disable-line:no-empty |
File renamed without changes.