-
-
Notifications
You must be signed in to change notification settings - Fork 594
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 #2007 from vuejs/prettier-pug
Add prettier-pug and fix region parser. Fix #527
- Loading branch information
Showing
10 changed files
with
202 additions
and
7 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
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,52 @@ | ||
import { TextDocument, Position, Range } from 'vscode-languageserver-types'; | ||
import { LanguageMode } from '../../embeddedSupport/languageModes'; | ||
import { prettierify } from '../../utils/prettier'; | ||
import { VLSFormatConfig } from '../../config'; | ||
import { getFileFsPath } from '../../utils/paths'; | ||
|
||
export function getPugMode(): LanguageMode { | ||
let config: any = {}; | ||
|
||
return { | ||
getId() { | ||
return 'pug'; | ||
}, | ||
configure(c) { | ||
config = c; | ||
}, | ||
format(document, currRange, formattingOptions) { | ||
if (config.vetur.format.defaultFormatter['pug'] === 'none') { | ||
return []; | ||
} | ||
|
||
const { value, range } = getValueAndRange(document, currRange); | ||
|
||
const foo = prettierify( | ||
value, | ||
getFileFsPath(document.uri), | ||
range, | ||
config.vetur.format as VLSFormatConfig, | ||
'pug', | ||
false | ||
); | ||
|
||
return foo; | ||
}, | ||
onDocumentRemoved() {}, | ||
dispose() {} | ||
}; | ||
} | ||
|
||
function getValueAndRange(document: TextDocument, currRange: Range): { value: string; range: Range } { | ||
let value = document.getText(); | ||
let range = currRange; | ||
|
||
if (currRange) { | ||
const startOffset = document.offsetAt(currRange.start); | ||
const endOffset = document.offsetAt(currRange.end); | ||
value = value.substring(startOffset, endOffset); | ||
} else { | ||
range = Range.create(Position.create(0, 0), document.positionAt(value.length)); | ||
} | ||
return { value, range }; | ||
} |
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