-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from tintinweb/auto-formatting
Auto formatting
- Loading branch information
Showing
5 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,42 @@ | ||
import { parse } from "@ts-graphviz/parser"; | ||
import { toDot } from "ts-graphviz"; | ||
import { | ||
DocumentFormattingEditProvider, | ||
// FormattingOptions, | ||
Position, | ||
ProviderResult, | ||
Range, | ||
TextDocument, | ||
TextEdit, | ||
window, | ||
} from "vscode"; | ||
|
||
export default class DotDocumentFormatter implements DocumentFormattingEditProvider { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
// eslint-disable-next-line class-methods-use-this | ||
provideDocumentFormattingEdits( | ||
document: TextDocument, | ||
// options: FormattingOptions, | ||
// token: CancellationToken, | ||
): ProviderResult<TextEdit[]> { | ||
try { | ||
const d = parse(document.getText()); | ||
const dot = toDot(d); | ||
|
||
const edit: TextEdit[] = []; | ||
edit.push(new TextEdit( | ||
new Range( | ||
new Position(0, 0), | ||
new Position(document.lineCount - 1, document.lineAt(document.lineCount - 1).text.length), | ||
), | ||
dot, | ||
)); | ||
return edit; | ||
} catch (e: any) { | ||
// (parser error) don't bubble up as a pot. unhandled thenable promise; | ||
// explicitly return "no change" instead. | ||
// show error message | ||
window.showErrorMessage(`${e.name} (@${e.location.start.line}:${e.location.start.column}): ${e.message}`); | ||
return undefined; | ||
} | ||
} | ||
} |
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 formatter did too much.
e.g. it did an auto sort and add quotes for all node.
it is good but should be optional.