-
-
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.
Document formatting provider added (#78)
- Loading branch information
Showing
13 changed files
with
784 additions
and
776 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as vscode from "vscode"; | ||
export class DocumentFilter implements vscode.DocumentFilter | ||
{ | ||
language?: string; | ||
|
||
scheme?: string; | ||
|
||
pattern?: vscode.GlobPattern; | ||
|
||
constructor(language?: string, scheme?: string, pattern?: vscode.GlobPattern) | ||
{ | ||
this.language = language ?? undefined; | ||
this.scheme = scheme ?? undefined; | ||
this.pattern = pattern ?? 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
// imports | ||
import * as vscode from "vscode"; | ||
import { DocumentFilter } from "./documentFilter"; | ||
export class DocumentHelper | ||
{ | ||
constructor() | ||
{ | ||
|
||
} | ||
|
||
|
||
public static get Editor() | ||
{ | ||
return vscode.window.activeTextEditor; | ||
} | ||
|
||
//get Range of the active document | ||
public static getEditorRange(): vscode.Range | ||
{ | ||
if (this.Editor) | ||
{ | ||
//get editor text | ||
let document = this.Editor.document; | ||
var start = new vscode.Position(0, 0); | ||
var lastButOne = document.lineAt(document.lineCount - 1); | ||
var end = new vscode.Position(document.lineCount, lastButOne.range.end.character); | ||
var ranger = new vscode.Range(start, end); | ||
return ranger; | ||
} | ||
else | ||
{ | ||
return new vscode.Range(0, 0, 0, 0); | ||
} | ||
} | ||
|
||
public static getDocumentText(): string | ||
{ | ||
if (this.Editor) | ||
{ | ||
return this.Editor.document.getText(); | ||
} | ||
else | ||
{ | ||
throw new Error("Editor not found!"); | ||
} | ||
} | ||
|
||
public static replaceTextForRange(range: vscode.Range, newText: string) | ||
{ | ||
if (this.Editor) | ||
{ | ||
this.Editor.edit(editBuilder => | ||
{ | ||
editBuilder.replace(range, newText); | ||
}); | ||
} | ||
} | ||
|
||
public static replaceDocumentText(newText: string) | ||
{ | ||
if (this.Editor) | ||
{ | ||
var range = this.getEditorRange(); | ||
this.Editor.edit(editBuilder => | ||
{ | ||
editBuilder.replace(range, newText); | ||
}); | ||
} | ||
} | ||
|
||
public static createLanguageDocumentFilters(language : string): vscode.DocumentFilter[] | ||
{ | ||
var filters = [ new DocumentFilter(language, 'file'), new DocumentFilter(language, 'untitled') ]; | ||
return filters; | ||
} | ||
} |
Oops, something went wrong.