-
-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sass Formatter #1434
Closed
Closed
Sass Formatter #1434
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b07d945
[added] SassLanguageMode
TheRealSyler e8647dc
[Sass Formatter] added options
TheRealSyler 7165565
Update-Package.json
TheRealSyler ab85393
--fix !?
TheRealSyler 62df71c
Add test and docs
octref 0970fcc
added SassFormatterConfig
TheRealSyler 89df8c0
Fixed link in formatting docs
TheRealSyler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ export type LanguageId = | |
| 'css' | ||
| 'postcss' | ||
| 'scss' | ||
| 'sass' | ||
| 'less' | ||
| 'stylus' | ||
| 'javascript' | ||
|
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,78 @@ | ||
import { LanguageMode } from '../../../embeddedSupport/languageModes'; | ||
|
||
import { TextDocument, Range, FormattingOptions, CompletionList } from 'vscode-languageserver-types/lib/umd/main'; | ||
|
||
import { Position, TextEdit } from 'vscode-css-languageservice'; | ||
|
||
import { DocumentContext } from '../../../types'; | ||
|
||
import { SassFormatter, SassTextDocument, SassFormatterConfig } from 'sass-formatter'; | ||
|
||
export class SassLanguageMode implements LanguageMode { | ||
private config: any = {}; | ||
|
||
constructor() {} | ||
|
||
getId() { | ||
return 'sass'; | ||
} | ||
|
||
configure(c: any) { | ||
this.config = c; | ||
} | ||
|
||
doValidation(document: TextDocument): any { | ||
return undefined; | ||
} | ||
doComplete(document: TextDocument, position: Position) { | ||
return CompletionList.create(); | ||
} | ||
doHover(document: TextDocument, position: Position): any { | ||
return undefined; | ||
} | ||
findDocumentHighlight(document: TextDocument, position: Position) { | ||
return []; | ||
} | ||
findDocumentLinks(document: TextDocument, documentContext: DocumentContext) { | ||
return []; | ||
} | ||
findDocumentSymbols(document: TextDocument) { | ||
return []; | ||
} | ||
format(document: TextDocument, range: Range, formattingOptions: FormattingOptions) { | ||
const sassConfig: SassFormatterConfig = { | ||
convert: true, | ||
deleteCompact: true, | ||
deleteEmptyRows: true, | ||
deleteWhitespace: true, | ||
replaceSpacesOrTabs: true, | ||
setPropertySpace: true | ||
}; | ||
Object.assign(this.config.sass.format, sassConfig); | ||
return [ | ||
TextEdit.replace( | ||
range, | ||
SassFormatter.Format( | ||
new SassTextDocument(document.getText(range)), | ||
{ | ||
insertSpaces: formattingOptions.insertSpaces, | ||
tabSize: formattingOptions.tabSize | ||
}, | ||
{ | ||
convert: this.config.sass.format.convert, | ||
deleteCompact: this.config.sass.format.deleteCompact, | ||
deleteEmptyRows: this.config.sass.format.deleteEmptyRows, | ||
deleteWhitespace: this.config.sass.format.deleteWhitespace, | ||
replaceSpacesOrTabs: this.config.sass.format.replaceSpacesOrTabs, | ||
setPropertySpace: this.config.sass.format.setPropertySpace | ||
} | ||
) | ||
) | ||
]; | ||
} | ||
findDefinition(document: TextDocument, position: Position): any { | ||
return undefined; | ||
} | ||
onDocumentRemoved(document: TextDocument) {} | ||
dispose() {} | ||
} |
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 |
---|---|---|
|
@@ -3911,6 +3911,13 @@ safe-regex@^1.1.0: | |
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" | ||
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== | ||
|
||
sass-formatter@^0.0.5: | ||
version "0.0.5" | ||
resolved "https://registry.yarnpkg.com/sass-formatter/-/sass-formatter-0.0.5.tgz#a5607119126d2b3e44c7557808c89d4ad0db3ec8" | ||
integrity sha512-7wQWezrnsV4pIcyOJxb4iYEDUV32hQMQDXf++YeAqMZ6iFjFf5dwGtjSeuxZpTc9ql0RtJEI6TVb5If7NvHE1A== | ||
dependencies: | ||
suf-regex "^0.0.2" | ||
|
||
[email protected]: | ||
version "0.5.8" | ||
resolved "https://registry.yarnpkg.com/sax/-/sax-0.5.8.tgz#d472db228eb331c2506b0e8c15524adb939d12c1" | ||
|
@@ -4282,6 +4289,11 @@ stylus@^0.54.5: | |
sax "0.5.x" | ||
source-map "0.1.x" | ||
|
||
suf-regex@^0.0.2: | ||
version "0.0.2" | ||
resolved "https://registry.yarnpkg.com/suf-regex/-/suf-regex-0.0.2.tgz#d15a2b5a0efccb5d7ef396f9c7d88224e909ed0b" | ||
integrity sha512-ntDtKKE6sYUOzjULRNlPrs5ln/SMJ1J/ygSZrk+CYdxmT6UKOGH8wJHjJCibBaPkszK6LICs6KWgt0P/Yllk/A== | ||
|
||
[email protected]: | ||
version "5.4.0" | ||
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.4.0.tgz#1c6b337402c2137605efe19f10fec390f6faab54" | ||
|
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,8 @@ | ||
<style lang="sass"> | ||
.foo | ||
color: blue | ||
|
||
.bar | ||
|
||
position: static | ||
</style> |
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 @@ | ||
<style lang="sass"> | ||
.foo { | ||
color: blue; | ||
} | ||
|
||
.bar | ||
|
||
|
||
position: static | ||
</style> |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you extract this into an interface exported from this file? We might have a default config at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i already made the interface here, i can just import the it from
sass-formatter
, maintaining two instances of the same interface seems unnecessary.