-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#69) add format on save configuration
- Loading branch information
1 parent
644d547
commit c8a6538
Showing
8 changed files
with
66 additions
and
8 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
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
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
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
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,10 @@ | ||
import { TextDocument } from 'vscode'; | ||
|
||
export class SupportLanguage { | ||
public static isSupportedLanguage(document: TextDocument | undefined): boolean { | ||
if (!document || document.languageId === null) { | ||
return false; | ||
} | ||
return (document.languageId === 'markdown' || document.languageId === 'mdx' || document.languageId === 'quarto'); | ||
} | ||
} |
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,29 @@ | ||
import { ExtensionContext, window, Disposable, TextDocumentWillSaveEvent, commands, workspace } from 'vscode'; | ||
import { SupportLanguage } from '../definitions/supportLanguage'; | ||
|
||
export class FormatOnSaveService implements Disposable { | ||
|
||
public constructor() { } | ||
|
||
public activate(context: ExtensionContext) { | ||
context.subscriptions.push( | ||
workspace.onWillSaveTextDocument((event) => this.onWillSaveTextDocument(event)) | ||
); | ||
} | ||
|
||
public dispose(): void { } | ||
|
||
private onWillSaveTextDocument(event: TextDocumentWillSaveEvent): void { | ||
let isSupportedLanguage = SupportLanguage.isSupportedLanguage(event.document); | ||
if (!isSupportedLanguage) { | ||
return; | ||
} | ||
|
||
let formatOnSave = <boolean>workspace.getConfiguration("markdowntable").get("formatOnSave"); | ||
if (!formatOnSave) { | ||
return; | ||
} | ||
|
||
commands.executeCommand("markdowntable.format"); | ||
} | ||
} |
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
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,7 @@ | ||
# title | ||
|
||
| column A | column B | column C | | ||
| :------- | :------- | :------- | | ||
| data | data | data | | ||
| data | | | | ||
| | | | |