Revamping to matrix style
This commit is contained in:
21
node_modules/volar-service-prettier/LICENSE
generated
vendored
Normal file
21
node_modules/volar-service-prettier/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022-present Pacharapol Withayasakpunt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
37
node_modules/volar-service-prettier/README.md
generated
vendored
Normal file
37
node_modules/volar-service-prettier/README.md
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
# volar-service-prettier
|
||||
|
||||
Volar plugin for [prettier](https://prettier.io/).
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install volar-service-prettier
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
`volar.config.js`
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
services: [
|
||||
require('volar-service-prettier').create(
|
||||
{
|
||||
languages: ['html', 'css', 'scss', 'typescript', 'javascript'],
|
||||
html: {
|
||||
breakContentsFromTags: true,
|
||||
},
|
||||
ignoreIdeOptions: true,
|
||||
},
|
||||
// provide your prettier options, otherwise auto resolve config file by plugin
|
||||
() => ({
|
||||
// ...
|
||||
})
|
||||
),
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE) © [Pacharapol Withayasakpunt](https://www.polv.cc)
|
||||
26
node_modules/volar-service-prettier/index.d.ts
generated
vendored
Normal file
26
node_modules/volar-service-prettier/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { DocumentSelector, FormattingOptions, ProviderResult, LanguageServiceContext, LanguageServicePlugin, TextDocument } from '@volar/language-service';
|
||||
import type { Options } from 'prettier';
|
||||
export declare function create(
|
||||
/**
|
||||
* Prettier instance or getter to use.
|
||||
*/
|
||||
prettierInstanceOrGetter: typeof import('prettier') | ((context: LanguageServiceContext) => ProviderResult<typeof import('prettier') | undefined>), { html, documentSelector, isFormattingEnabled, getFormattingOptions, }?: {
|
||||
html?: {
|
||||
/**
|
||||
* Preprocessing to break "contents" from "HTML tags".
|
||||
* This will prevent HTML closing tags, and opening tags without attributes
|
||||
* from breaking into a blank `>` or `<` on a new line.
|
||||
*/
|
||||
breakContentsFromTags?: boolean;
|
||||
};
|
||||
/**
|
||||
* Languages to be formatted by prettier.
|
||||
*
|
||||
* @default
|
||||
* ['html', 'css', 'scss', 'typescript', 'javascript']
|
||||
*/
|
||||
documentSelector?: DocumentSelector;
|
||||
isFormattingEnabled?(prettier: typeof import('prettier'), document: TextDocument, context: LanguageServiceContext): ProviderResult<boolean>;
|
||||
getFormattingOptions?(prettier: typeof import('prettier'), document: TextDocument, formatOptions: FormattingOptions, context: LanguageServiceContext): ProviderResult<Options>;
|
||||
}): LanguageServicePlugin;
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
89
node_modules/volar-service-prettier/index.js
generated
vendored
Normal file
89
node_modules/volar-service-prettier/index.js
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.create = create;
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
function create(
|
||||
/**
|
||||
* Prettier instance or getter to use.
|
||||
*/
|
||||
prettierInstanceOrGetter, { html, documentSelector = ['html', 'css', 'scss', 'typescript', 'javascript'], isFormattingEnabled = async (prettier, document, context) => {
|
||||
const parsed = vscode_uri_1.URI.parse(document.uri);
|
||||
const uri = context.decodeEmbeddedDocumentUri(parsed)?.[0] ?? parsed;
|
||||
if (uri.scheme === 'file') {
|
||||
const fileInfo = await prettier.getFileInfo(uri.fsPath, { ignorePath: '.prettierignore', resolveConfig: false });
|
||||
if (fileInfo.ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}, getFormattingOptions = async (prettier, document, formatOptions, context) => {
|
||||
const parsed = vscode_uri_1.URI.parse(document.uri);
|
||||
const uri = context.decodeEmbeddedDocumentUri(parsed)?.[0] ?? parsed;
|
||||
const configOptions = uri.scheme === 'file'
|
||||
? await prettier.resolveConfig(uri.fsPath)
|
||||
: null;
|
||||
const editorOptions = await context.env.getConfiguration?.('prettier', uri.toString());
|
||||
return {
|
||||
filepath: uri.scheme === 'file'
|
||||
? uri.fsPath
|
||||
: undefined,
|
||||
tabWidth: formatOptions.tabSize,
|
||||
useTabs: !formatOptions.insertSpaces,
|
||||
...editorOptions,
|
||||
...configOptions,
|
||||
};
|
||||
}, } = {}) {
|
||||
return {
|
||||
name: 'prettier',
|
||||
capabilities: {
|
||||
documentFormattingProvider: true,
|
||||
},
|
||||
create(context) {
|
||||
let prettierInstanceOrPromise;
|
||||
return {
|
||||
async provideDocumentFormattingEdits(document, _, formatOptions) {
|
||||
if (!matchDocument(documentSelector, document)) {
|
||||
return;
|
||||
}
|
||||
prettierInstanceOrPromise ??= typeof prettierInstanceOrGetter === 'function'
|
||||
? prettierInstanceOrGetter(context)
|
||||
: prettierInstanceOrGetter;
|
||||
const prettier = await prettierInstanceOrPromise;
|
||||
if (!prettier) {
|
||||
return;
|
||||
}
|
||||
const hasFormattingEnabled = await isFormattingEnabled(prettier, document, context);
|
||||
if (!hasFormattingEnabled) {
|
||||
return;
|
||||
}
|
||||
const fullText = document.getText();
|
||||
let oldText = fullText;
|
||||
const isHTML = document.languageId === 'html';
|
||||
if (isHTML && html?.breakContentsFromTags) {
|
||||
oldText = oldText
|
||||
.replace(/(<[a-z][^>]*>)([^ \n])/gi, '$1 $2')
|
||||
.replace(/([^ \n])(<\/[a-z][a-z0-9\t\n\r -]*>)/gi, '$1 $2');
|
||||
}
|
||||
const prettierOptions = await getFormattingOptions(prettier, document, formatOptions, context);
|
||||
const newText = await prettier.format(oldText, prettierOptions);
|
||||
return [{
|
||||
newText,
|
||||
range: {
|
||||
start: document.positionAt(0),
|
||||
end: document.positionAt(fullText.length),
|
||||
},
|
||||
}];
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
function matchDocument(selector, document) {
|
||||
for (const sel of selector) {
|
||||
if (sel === document.languageId || (typeof sel === 'object' && sel.language === document.languageId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
47
node_modules/volar-service-prettier/package.json
generated
vendored
Normal file
47
node_modules/volar-service-prettier/package.json
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "volar-service-prettier",
|
||||
"version": "0.0.62",
|
||||
"description": "Integrate Prettier into Volar",
|
||||
"homepage": "https://github.com/volarjs/services/tree/master/packages/prettier",
|
||||
"bugs": "https://github.com/volarjs/services/issues",
|
||||
"sideEffects": false,
|
||||
"keywords": [
|
||||
"volar-service"
|
||||
],
|
||||
"types": "out/index.d.ts",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"**/*.js",
|
||||
"**/*.d.ts"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/volarjs/services.git",
|
||||
"directory": "packages/prettier"
|
||||
},
|
||||
"author": {
|
||||
"name": "Pacharapol Withayasakpunt",
|
||||
"email": "polv@polv.cc",
|
||||
"url": "https://www.polv.cc"
|
||||
},
|
||||
"dependencies": {
|
||||
"vscode-uri": "^3.0.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "latest",
|
||||
"prettier": "^3.3.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@volar/language-service": "~2.4.0",
|
||||
"prettier": "^2.2 || ^3.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"prettier": {
|
||||
"optional": true
|
||||
},
|
||||
"@volar/language-service": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"gitHead": "f1ddbdc4d9df0772db5a0d46ff8ff64eecc9de02"
|
||||
}
|
||||
10
node_modules/volar-service-prettier/sample/volar.config.js
generated
vendored
Normal file
10
node_modules/volar-service-prettier/sample/volar.config.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
services: [
|
||||
require('..')({
|
||||
html: {
|
||||
// breakContentsFromTags: true,
|
||||
},
|
||||
// ignoreIdeOptions: true,
|
||||
}),
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user