|
1 | 1 | 'use strict'; |
2 | 2 | import * as vscode from 'vscode'; |
3 | | -import { getDocumentRangePrettyfier, getDocumentPrettyfier, getDocumentPrettyfierCommand } from './prettyfierFactory'; |
| 3 | +import { getSupportLanguageIds, getDocumentRangePrettyfier, getDocumentPrettyfier, getDocumentPrettyfierCommand } from './prettyfierFactory'; |
4 | 4 |
|
5 | 5 | // This method is called when the extension is activated. |
6 | 6 | // The extension is activated the very first time the command is executed. |
7 | 7 | export function activate(context: vscode.ExtensionContext): void { |
8 | | - const MD_MODE: vscode.DocumentFilter = { language: "markdown" }; |
9 | | - const command = "markdownTablePrettify.prettifyTables"; |
10 | 8 |
|
| 9 | + const supportedLanguageIds = getSupportLanguageIds(); |
| 10 | + for (let language of supportedLanguageIds) { |
| 11 | + context.subscriptions.push( |
| 12 | + vscode.languages.registerDocumentRangeFormattingEditProvider({ language }, getDocumentRangePrettyfier()), |
| 13 | + vscode.languages.registerDocumentFormattingEditProvider({ language }, getDocumentPrettyfier()) |
| 14 | + ); |
| 15 | + } |
| 16 | + |
| 17 | + const command = "markdownTablePrettify.prettifyTables"; |
11 | 18 | context.subscriptions.push( |
12 | | - vscode.languages.registerDocumentRangeFormattingEditProvider(MD_MODE, getDocumentRangePrettyfier()), |
13 | | - vscode.languages.registerDocumentFormattingEditProvider(MD_MODE, getDocumentPrettyfier()), |
14 | | - vscode.commands.registerTextEditorCommand(command, textEditor => getDocumentPrettyfierCommand().prettifyDocument(textEditor)) |
| 19 | + vscode.commands.registerTextEditorCommand(command, textEditor => { |
| 20 | + if (supportedLanguageIds.indexOf(textEditor.document.languageId) >= 0) |
| 21 | + getDocumentPrettyfierCommand().prettifyDocument(textEditor); |
| 22 | + }) |
15 | 23 | ); |
16 | 24 | } |
17 | 25 |
|
|
0 commit comments