🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
45
node_modules/@astrojs/language-server/dist/plugins/css/CSSDocument.d.ts
generated
vendored
Normal file
45
node_modules/@astrojs/language-server/dist/plugins/css/CSSDocument.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import type { Stylesheet, TextDocument } from 'vscode-css-languageservice';
|
||||
import type { Position } from 'vscode-languageserver';
|
||||
import { AstroDocument, DocumentMapper, ReadableDocument, TagInformation } from '../../core/documents';
|
||||
export interface CSSDocumentBase extends DocumentMapper, TextDocument {
|
||||
languageId: string;
|
||||
stylesheet: Stylesheet;
|
||||
}
|
||||
export declare class CSSDocument extends ReadableDocument implements DocumentMapper {
|
||||
private parent;
|
||||
private styleInfo;
|
||||
readonly version: number;
|
||||
stylesheet: Stylesheet;
|
||||
languageId: string;
|
||||
constructor(parent: AstroDocument, styleInfo: Pick<TagInformation, 'attributes' | 'start' | 'end'>);
|
||||
/**
|
||||
* Get the fragment position relative to the parent
|
||||
* @param pos Position in fragment
|
||||
*/
|
||||
getOriginalPosition(pos: Position): Position;
|
||||
/**
|
||||
* Get the position relative to the start of the fragment
|
||||
* @param pos Position in parent
|
||||
*/
|
||||
getGeneratedPosition(pos: Position): Position;
|
||||
/**
|
||||
* Returns true if the given parent position is inside of this fragment
|
||||
* @param pos Position in parent
|
||||
*/
|
||||
isInGenerated(pos: Position): boolean;
|
||||
/**
|
||||
* Get the fragment text from the parent
|
||||
*/
|
||||
getText(): string;
|
||||
/**
|
||||
* Returns the length of the fragment as calculated from the start and end position
|
||||
*/
|
||||
getTextLength(): number;
|
||||
/**
|
||||
* Return the parent file path
|
||||
*/
|
||||
getFilePath(): string | null;
|
||||
getURL(): string;
|
||||
getAttributes(): Record<string, string>;
|
||||
private get language();
|
||||
}
|
||||
68
node_modules/@astrojs/language-server/dist/plugins/css/CSSDocument.js
generated
vendored
Normal file
68
node_modules/@astrojs/language-server/dist/plugins/css/CSSDocument.js
generated
vendored
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CSSDocument = void 0;
|
||||
const documents_1 = require("../../core/documents");
|
||||
const language_service_1 = require("./language-service");
|
||||
class CSSDocument extends documents_1.ReadableDocument {
|
||||
constructor(parent, styleInfo) {
|
||||
super();
|
||||
this.parent = parent;
|
||||
this.styleInfo = styleInfo;
|
||||
this.version = this.parent.version;
|
||||
this.languageId = this.language;
|
||||
this.stylesheet = (0, language_service_1.getLanguageService)(this.language).parseStylesheet(this);
|
||||
}
|
||||
/**
|
||||
* Get the fragment position relative to the parent
|
||||
* @param pos Position in fragment
|
||||
*/
|
||||
getOriginalPosition(pos) {
|
||||
const parentOffset = this.styleInfo.start + this.offsetAt(pos);
|
||||
return this.parent.positionAt(parentOffset);
|
||||
}
|
||||
/**
|
||||
* Get the position relative to the start of the fragment
|
||||
* @param pos Position in parent
|
||||
*/
|
||||
getGeneratedPosition(pos) {
|
||||
const fragmentOffset = this.parent.offsetAt(pos) - this.styleInfo.start;
|
||||
return this.positionAt(fragmentOffset);
|
||||
}
|
||||
/**
|
||||
* Returns true if the given parent position is inside of this fragment
|
||||
* @param pos Position in parent
|
||||
*/
|
||||
isInGenerated(pos) {
|
||||
const offset = this.parent.offsetAt(pos);
|
||||
return offset >= this.styleInfo.start && offset <= this.styleInfo.end;
|
||||
}
|
||||
/**
|
||||
* Get the fragment text from the parent
|
||||
*/
|
||||
getText() {
|
||||
return this.parent.getText().slice(this.styleInfo.start, this.styleInfo.end);
|
||||
}
|
||||
/**
|
||||
* Returns the length of the fragment as calculated from the start and end position
|
||||
*/
|
||||
getTextLength() {
|
||||
return this.styleInfo.end - this.styleInfo.start;
|
||||
}
|
||||
/**
|
||||
* Return the parent file path
|
||||
*/
|
||||
getFilePath() {
|
||||
return this.parent.getFilePath();
|
||||
}
|
||||
getURL() {
|
||||
return this.parent.getURL();
|
||||
}
|
||||
getAttributes() {
|
||||
return this.styleInfo.attributes;
|
||||
}
|
||||
get language() {
|
||||
const attrs = this.getAttributes();
|
||||
return attrs.lang || attrs.type || 'css';
|
||||
}
|
||||
}
|
||||
exports.CSSDocument = CSSDocument;
|
||||
39
node_modules/@astrojs/language-server/dist/plugins/css/CSSPlugin.d.ts
generated
vendored
Normal file
39
node_modules/@astrojs/language-server/dist/plugins/css/CSSPlugin.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { Color, ColorInformation, ColorPresentation, CompletionContext, CompletionList, FoldingRange, Hover, Position, Range, SymbolInformation, WorkspaceEdit } from 'vscode-languageserver';
|
||||
import type { ConfigManager } from '../../core/config/ConfigManager';
|
||||
import { AstroDocument } from '../../core/documents';
|
||||
import type { Plugin } from '../interfaces';
|
||||
export declare class CSSPlugin implements Plugin {
|
||||
__name: string;
|
||||
private configManager;
|
||||
private cssDocuments;
|
||||
private triggerCharacters;
|
||||
constructor(configManager: ConfigManager);
|
||||
doHover(document: AstroDocument, position: Position): Promise<Hover | null>;
|
||||
private doHoverInternal;
|
||||
getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext): Promise<CompletionList | null>;
|
||||
private getCompletionsInternal;
|
||||
getDocumentColors(document: AstroDocument): Promise<ColorInformation[]>;
|
||||
getColorPresentations(document: AstroDocument, range: Range, color: Color): Promise<ColorPresentation[]>;
|
||||
prepareRename(document: AstroDocument, position: Position): Range | null;
|
||||
rename(document: AstroDocument, position: Position, newName: string): WorkspaceEdit | null;
|
||||
getFoldingRanges(document: AstroDocument): FoldingRange[] | null;
|
||||
getDocumentSymbols(document: AstroDocument): Promise<SymbolInformation[]>;
|
||||
private inStyleAttributeWithoutInterpolation;
|
||||
/**
|
||||
* Get the associated CSS Document for a style tag
|
||||
*/
|
||||
private getCSSDocumentForStyleTag;
|
||||
/**
|
||||
* Get all the CSSDocuments in a document
|
||||
*/
|
||||
private getCSSDocumentsForDocument;
|
||||
/**
|
||||
* Get all the stylesheets (Stylesheet type) in a document
|
||||
*/
|
||||
private getStylesheetsForDocument;
|
||||
/**
|
||||
* Get style tag at position for a document
|
||||
*/
|
||||
private getStyleTagForPosition;
|
||||
private featureEnabled;
|
||||
}
|
||||
274
node_modules/@astrojs/language-server/dist/plugins/css/CSSPlugin.js
generated
vendored
Normal file
274
node_modules/@astrojs/language-server/dist/plugins/css/CSSPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,274 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CSSPlugin = void 0;
|
||||
const emmet_helper_1 = require("@vscode/emmet-helper");
|
||||
const vscode_languageserver_1 = require("vscode-languageserver");
|
||||
const documents_1 = require("../../core/documents");
|
||||
const parseHtml_1 = require("../../core/documents/parseHtml");
|
||||
const CSSDocument_1 = require("./CSSDocument");
|
||||
const getIdClassCompletions_1 = require("./features/getIdClassCompletions");
|
||||
const language_service_1 = require("./language-service");
|
||||
const StyleAttributeDocument_1 = require("./StyleAttributeDocument");
|
||||
class CSSPlugin {
|
||||
constructor(configManager) {
|
||||
this.__name = 'css';
|
||||
this.cssDocuments = new WeakMap();
|
||||
this.triggerCharacters = new Set(['.', ':', '-', '/']);
|
||||
this.configManager = configManager;
|
||||
}
|
||||
async doHover(document, position) {
|
||||
if (!(await this.featureEnabled(document, 'hover'))) {
|
||||
return null;
|
||||
}
|
||||
if ((0, documents_1.isInsideFrontmatter)(document.getText(), document.offsetAt(position))) {
|
||||
return null;
|
||||
}
|
||||
const styleTag = this.getStyleTagForPosition(document, position);
|
||||
// We technically can return results even for open tags, however, a lot of the info returned is not valid
|
||||
// Since most editors will automatically close the tag before the user start working in them, this shouldn't be a problem
|
||||
if (styleTag && !styleTag.closed) {
|
||||
return null;
|
||||
}
|
||||
// If we don't have a style tag at this position, we might be in a style property instead, let's check
|
||||
if (!styleTag) {
|
||||
const attributeContext = (0, parseHtml_1.getAttributeContextAtPosition)(document, position);
|
||||
if (!attributeContext) {
|
||||
return null;
|
||||
}
|
||||
if (this.inStyleAttributeWithoutInterpolation(attributeContext, document.getText())) {
|
||||
const [start, end] = attributeContext.valueRange;
|
||||
return this.doHoverInternal(new StyleAttributeDocument_1.StyleAttributeDocument(document, start, end), position);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const cssDocument = this.getCSSDocumentForStyleTag(styleTag, document);
|
||||
const cssLang = extractLanguage(cssDocument);
|
||||
if (!isSupportedByLangService(cssLang)) {
|
||||
return null;
|
||||
}
|
||||
return this.doHoverInternal(cssDocument, position);
|
||||
}
|
||||
doHoverInternal(cssDocument, position) {
|
||||
const hoverInfo = (0, language_service_1.getLanguageService)(extractLanguage(cssDocument)).doHover(cssDocument, cssDocument.getGeneratedPosition(position), cssDocument.stylesheet);
|
||||
return hoverInfo ? (0, documents_1.mapHoverToParent)(cssDocument, hoverInfo) : hoverInfo;
|
||||
}
|
||||
async getCompletions(document, position, completionContext) {
|
||||
if (!(await this.featureEnabled(document, 'completions'))) {
|
||||
return null;
|
||||
}
|
||||
if ((0, documents_1.isInsideFrontmatter)(document.getText(), document.offsetAt(position))) {
|
||||
return null;
|
||||
}
|
||||
const triggerCharacter = completionContext?.triggerCharacter;
|
||||
const triggerKind = completionContext?.triggerKind;
|
||||
const isCustomTriggerCharacter = triggerKind === vscode_languageserver_1.CompletionTriggerKind.TriggerCharacter;
|
||||
if (isCustomTriggerCharacter && triggerCharacter && !this.triggerCharacters.has(triggerCharacter)) {
|
||||
return null;
|
||||
}
|
||||
const styleTag = this.getStyleTagForPosition(document, position);
|
||||
if (styleTag && !styleTag.closed) {
|
||||
return null;
|
||||
}
|
||||
if (!styleTag) {
|
||||
const attributeContext = (0, parseHtml_1.getAttributeContextAtPosition)(document, position);
|
||||
if (!attributeContext) {
|
||||
return null;
|
||||
}
|
||||
if (this.inStyleAttributeWithoutInterpolation(attributeContext, document.getText())) {
|
||||
const [start, end] = attributeContext.valueRange;
|
||||
return await this.getCompletionsInternal(document, position, new StyleAttributeDocument_1.StyleAttributeDocument(document, start, end));
|
||||
}
|
||||
// If we're not in a style attribute, instead give completions for ids and classes used in the current document
|
||||
else if ((attributeContext.name == 'id' || attributeContext.name == 'class') && attributeContext.inValue) {
|
||||
const stylesheets = this.getStylesheetsForDocument(document);
|
||||
return (0, getIdClassCompletions_1.getIdClassCompletion)(stylesheets, attributeContext);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const cssDocument = this.getCSSDocumentForStyleTag(styleTag, document);
|
||||
return await this.getCompletionsInternal(document, position, cssDocument);
|
||||
}
|
||||
async getCompletionsInternal(document, position, cssDocument) {
|
||||
const emmetConfig = await this.configManager.getEmmetConfig(document);
|
||||
if (isSASS(cssDocument)) {
|
||||
// The CSS language service does not support SASS (not to be confused with SCSS)
|
||||
// however we can at least still at least provide Emmet completions in SASS blocks
|
||||
return (0, emmet_helper_1.doComplete)(document, position, 'sass', emmetConfig) || null;
|
||||
}
|
||||
const cssLang = extractLanguage(cssDocument);
|
||||
const langService = (0, language_service_1.getLanguageService)(cssLang);
|
||||
let emmetResults = {
|
||||
isIncomplete: false,
|
||||
items: [],
|
||||
};
|
||||
const extensionConfig = await this.configManager.getConfig('astro', document.uri);
|
||||
if (extensionConfig?.css?.completions?.emmet ?? true) {
|
||||
langService.setCompletionParticipants([
|
||||
{
|
||||
onCssProperty: (context) => {
|
||||
if (context?.propertyName) {
|
||||
emmetResults =
|
||||
(0, emmet_helper_1.doComplete)(cssDocument, cssDocument.getGeneratedPosition(position), (0, language_service_1.getLanguage)(cssLang), emmetConfig) || emmetResults;
|
||||
}
|
||||
},
|
||||
onCssPropertyValue: (context) => {
|
||||
if (context?.propertyValue) {
|
||||
emmetResults =
|
||||
(0, emmet_helper_1.doComplete)(cssDocument, cssDocument.getGeneratedPosition(position), (0, language_service_1.getLanguage)(cssLang), emmetConfig) || emmetResults;
|
||||
}
|
||||
},
|
||||
},
|
||||
]);
|
||||
}
|
||||
const results = langService.doComplete(cssDocument, cssDocument.getGeneratedPosition(position), cssDocument.stylesheet);
|
||||
return vscode_languageserver_1.CompletionList.create([...(results ? results.items : []), ...emmetResults.items].map((completionItem) => (0, documents_1.mapCompletionItemToOriginal)(cssDocument, completionItem)),
|
||||
// Emmet completions change on every keystroke, so they are never complete
|
||||
emmetResults.items.length > 0);
|
||||
}
|
||||
async getDocumentColors(document) {
|
||||
if (!(await this.featureEnabled(document, 'documentColors'))) {
|
||||
return [];
|
||||
}
|
||||
const allColorInfo = this.getCSSDocumentsForDocument(document).flatMap((cssDoc) => {
|
||||
const cssLang = extractLanguage(cssDoc);
|
||||
const langService = (0, language_service_1.getLanguageService)(cssLang);
|
||||
if (!isSupportedByLangService(cssLang)) {
|
||||
return [];
|
||||
}
|
||||
return langService
|
||||
.findDocumentColors(cssDoc, cssDoc.stylesheet)
|
||||
.map((colorInfo) => (0, documents_1.mapObjWithRangeToOriginal)(cssDoc, colorInfo));
|
||||
});
|
||||
return allColorInfo;
|
||||
}
|
||||
async getColorPresentations(document, range, color) {
|
||||
if (!(await this.featureEnabled(document, 'documentColors'))) {
|
||||
return [];
|
||||
}
|
||||
const allColorPres = this.getCSSDocumentsForDocument(document).flatMap((cssDoc) => {
|
||||
const cssLang = extractLanguage(cssDoc);
|
||||
const langService = (0, language_service_1.getLanguageService)(cssLang);
|
||||
if ((!cssDoc.isInGenerated(range.start) && !cssDoc.isInGenerated(range.end)) ||
|
||||
!isSupportedByLangService(cssLang)) {
|
||||
return [];
|
||||
}
|
||||
return langService
|
||||
.getColorPresentations(cssDoc, cssDoc.stylesheet, color, (0, documents_1.mapRangeToGenerated)(cssDoc, range))
|
||||
.map((colorPres) => (0, documents_1.mapColorPresentationToOriginal)(cssDoc, colorPres));
|
||||
});
|
||||
return allColorPres;
|
||||
}
|
||||
prepareRename(document, position) {
|
||||
const styleTag = this.getStyleTagForPosition(document, position);
|
||||
if (!styleTag) {
|
||||
return null;
|
||||
}
|
||||
const cssDocument = this.getCSSDocumentForStyleTag(styleTag, document);
|
||||
const cssLang = extractLanguage(cssDocument);
|
||||
const langService = (0, language_service_1.getLanguageService)(cssLang);
|
||||
const range = langService.prepareRename(cssDocument, cssDocument.getGeneratedPosition(position), cssDocument.stylesheet);
|
||||
if (!range) {
|
||||
return null;
|
||||
}
|
||||
return (0, documents_1.mapRangeToOriginal)(cssDocument, range);
|
||||
}
|
||||
rename(document, position, newName) {
|
||||
const styleTag = this.getStyleTagForPosition(document, position);
|
||||
if (!styleTag) {
|
||||
return null;
|
||||
}
|
||||
const cssDocument = this.getCSSDocumentForStyleTag(styleTag, document);
|
||||
const cssLang = extractLanguage(cssDocument);
|
||||
const langService = (0, language_service_1.getLanguageService)(cssLang);
|
||||
const renames = langService.doRename(cssDocument, cssDocument.getGeneratedPosition(position), newName, cssDocument.stylesheet);
|
||||
if (renames?.changes?.[document.uri]) {
|
||||
renames.changes[document.uri] = renames?.changes?.[document.uri].map((edit) => (0, documents_1.mapObjWithRangeToOriginal)(cssDocument, edit));
|
||||
}
|
||||
return renames;
|
||||
}
|
||||
getFoldingRanges(document) {
|
||||
const allFoldingRanges = this.getCSSDocumentsForDocument(document).flatMap((cssDoc) => {
|
||||
const cssLang = extractLanguage(cssDoc);
|
||||
const langService = (0, language_service_1.getLanguageService)(cssLang);
|
||||
return langService.getFoldingRanges(cssDoc).map((foldingRange) => (0, documents_1.mapFoldingRangeToParent)(cssDoc, foldingRange));
|
||||
});
|
||||
return allFoldingRanges;
|
||||
}
|
||||
async getDocumentSymbols(document) {
|
||||
if (!(await this.featureEnabled(document, 'documentSymbols'))) {
|
||||
return [];
|
||||
}
|
||||
const allDocumentSymbols = this.getCSSDocumentsForDocument(document).flatMap((cssDoc) => {
|
||||
return (0, language_service_1.getLanguageService)(extractLanguage(cssDoc))
|
||||
.findDocumentSymbols(cssDoc, cssDoc.stylesheet)
|
||||
.map((symbol) => (0, documents_1.mapSymbolInformationToOriginal)(cssDoc, symbol));
|
||||
});
|
||||
return allDocumentSymbols;
|
||||
}
|
||||
inStyleAttributeWithoutInterpolation(attrContext, text) {
|
||||
return (attrContext.name === 'style' &&
|
||||
!!attrContext.valueRange &&
|
||||
!text.substring(attrContext.valueRange[0], attrContext.valueRange[1]).includes('{'));
|
||||
}
|
||||
/**
|
||||
* Get the associated CSS Document for a style tag
|
||||
*/
|
||||
getCSSDocumentForStyleTag(tag, document) {
|
||||
let cssDoc = this.cssDocuments.get(tag);
|
||||
if (!cssDoc || cssDoc.version < document.version) {
|
||||
cssDoc = new CSSDocument_1.CSSDocument(document, tag);
|
||||
this.cssDocuments.set(tag, cssDoc);
|
||||
}
|
||||
return cssDoc;
|
||||
}
|
||||
/**
|
||||
* Get all the CSSDocuments in a document
|
||||
*/
|
||||
getCSSDocumentsForDocument(document) {
|
||||
return document.styleTags.map((tag) => this.getCSSDocumentForStyleTag(tag, document));
|
||||
}
|
||||
/**
|
||||
* Get all the stylesheets (Stylesheet type) in a document
|
||||
*/
|
||||
getStylesheetsForDocument(document) {
|
||||
return this.getCSSDocumentsForDocument(document).map((cssDoc) => cssDoc.stylesheet);
|
||||
}
|
||||
/**
|
||||
* Get style tag at position for a document
|
||||
*/
|
||||
getStyleTagForPosition(document, position) {
|
||||
return document.styleTags.find((styleTag) => {
|
||||
return (0, documents_1.isInTag)(position, styleTag);
|
||||
});
|
||||
}
|
||||
async featureEnabled(document, feature) {
|
||||
return ((await this.configManager.isEnabled(document, 'css')) &&
|
||||
(await this.configManager.isEnabled(document, 'css', feature)));
|
||||
}
|
||||
}
|
||||
exports.CSSPlugin = CSSPlugin;
|
||||
/**
|
||||
* Check is a CSSDocument's language is supported by the CSS language service
|
||||
*/
|
||||
function isSupportedByLangService(language) {
|
||||
switch (language) {
|
||||
case 'css':
|
||||
case 'scss':
|
||||
case 'less':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function isSASS(document) {
|
||||
switch (extractLanguage(document)) {
|
||||
case 'sass':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function extractLanguage(document) {
|
||||
const lang = document.languageId;
|
||||
return lang.replace(/^text\//, '');
|
||||
}
|
||||
40
node_modules/@astrojs/language-server/dist/plugins/css/StyleAttributeDocument.d.ts
generated
vendored
Normal file
40
node_modules/@astrojs/language-server/dist/plugins/css/StyleAttributeDocument.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import type { Stylesheet } from 'vscode-css-languageservice';
|
||||
import type { Position } from 'vscode-languageserver';
|
||||
import { AstroDocument, DocumentMapper, ReadableDocument } from '../../core/documents';
|
||||
export declare class StyleAttributeDocument extends ReadableDocument implements DocumentMapper {
|
||||
private readonly parent;
|
||||
private readonly attrStart;
|
||||
private readonly attrEnd;
|
||||
readonly version: number;
|
||||
stylesheet: Stylesheet;
|
||||
languageId: string;
|
||||
constructor(parent: AstroDocument, attrStart: number, attrEnd: number);
|
||||
/**
|
||||
* Get the fragment position relative to the parent
|
||||
* @param pos Position in fragment
|
||||
*/
|
||||
getOriginalPosition(pos: Position): Position;
|
||||
/**
|
||||
* Get the position relative to the start of the fragment
|
||||
* @param pos Position in parent
|
||||
*/
|
||||
getGeneratedPosition(pos: Position): Position;
|
||||
/**
|
||||
* Returns true if the given parent position is inside of this fragment
|
||||
* @param pos Position in parent
|
||||
*/
|
||||
isInGenerated(pos: Position): boolean;
|
||||
/**
|
||||
* Get the fragment text from the parent
|
||||
*/
|
||||
getText(): string;
|
||||
/**
|
||||
* Returns the length of the fragment as calculated from the start and end position
|
||||
*/
|
||||
getTextLength(): number;
|
||||
/**
|
||||
* Return the parent file path
|
||||
*/
|
||||
getFilePath(): string | null;
|
||||
getURL(): string;
|
||||
}
|
||||
64
node_modules/@astrojs/language-server/dist/plugins/css/StyleAttributeDocument.js
generated
vendored
Normal file
64
node_modules/@astrojs/language-server/dist/plugins/css/StyleAttributeDocument.js
generated
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.StyleAttributeDocument = void 0;
|
||||
const documents_1 = require("../../core/documents");
|
||||
const language_service_1 = require("./language-service");
|
||||
const PREFIX = '__ {';
|
||||
const SUFFIX = '}';
|
||||
class StyleAttributeDocument extends documents_1.ReadableDocument {
|
||||
constructor(parent, attrStart, attrEnd) {
|
||||
super();
|
||||
this.parent = parent;
|
||||
this.attrStart = attrStart;
|
||||
this.attrEnd = attrEnd;
|
||||
this.version = this.parent.version;
|
||||
this.languageId = 'css';
|
||||
this.stylesheet = (0, language_service_1.getLanguageService)(this.languageId).parseStylesheet(this);
|
||||
}
|
||||
/**
|
||||
* Get the fragment position relative to the parent
|
||||
* @param pos Position in fragment
|
||||
*/
|
||||
getOriginalPosition(pos) {
|
||||
const parentOffset = this.attrStart + this.offsetAt(pos) - PREFIX.length;
|
||||
return this.parent.positionAt(parentOffset);
|
||||
}
|
||||
/**
|
||||
* Get the position relative to the start of the fragment
|
||||
* @param pos Position in parent
|
||||
*/
|
||||
getGeneratedPosition(pos) {
|
||||
const fragmentOffset = this.parent.offsetAt(pos) - this.attrStart + PREFIX.length;
|
||||
return this.positionAt(fragmentOffset);
|
||||
}
|
||||
/**
|
||||
* Returns true if the given parent position is inside of this fragment
|
||||
* @param pos Position in parent
|
||||
*/
|
||||
isInGenerated(pos) {
|
||||
const offset = this.parent.offsetAt(pos);
|
||||
return offset >= this.attrStart && offset <= this.attrEnd;
|
||||
}
|
||||
/**
|
||||
* Get the fragment text from the parent
|
||||
*/
|
||||
getText() {
|
||||
return PREFIX + this.parent.getText().slice(this.attrStart, this.attrEnd) + SUFFIX;
|
||||
}
|
||||
/**
|
||||
* Returns the length of the fragment as calculated from the start and end position
|
||||
*/
|
||||
getTextLength() {
|
||||
return PREFIX.length + this.attrEnd - this.attrStart + SUFFIX.length;
|
||||
}
|
||||
/**
|
||||
* Return the parent file path
|
||||
*/
|
||||
getFilePath() {
|
||||
return this.parent.getFilePath();
|
||||
}
|
||||
getURL() {
|
||||
return this.parent.getURL();
|
||||
}
|
||||
}
|
||||
exports.StyleAttributeDocument = StyleAttributeDocument;
|
||||
2
node_modules/@astrojs/language-server/dist/plugins/css/features/astro-selectors.d.ts
generated
vendored
Normal file
2
node_modules/@astrojs/language-server/dist/plugins/css/features/astro-selectors.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import type { IPseudoClassData } from 'vscode-css-languageservice';
|
||||
export declare const pseudoClass: IPseudoClassData[];
|
||||
15
node_modules/@astrojs/language-server/dist/plugins/css/features/astro-selectors.js
generated
vendored
Normal file
15
node_modules/@astrojs/language-server/dist/plugins/css/features/astro-selectors.js
generated
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.pseudoClass = void 0;
|
||||
exports.pseudoClass = [
|
||||
{
|
||||
name: ':global()',
|
||||
description: 'Apply styles to a selector globally',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro documentation',
|
||||
url: 'https://docs.astro.build/en/guides/styling/#global-styles-within-style-tag',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
19
node_modules/@astrojs/language-server/dist/plugins/css/features/getIdClassCompletions.d.ts
generated
vendored
Normal file
19
node_modules/@astrojs/language-server/dist/plugins/css/features/getIdClassCompletions.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import type { Stylesheet } from 'vscode-css-languageservice';
|
||||
import { CompletionItem, CompletionList } from 'vscode-languageserver';
|
||||
import type { AttributeContext } from '../../../core/documents/parseHtml';
|
||||
export declare function getIdClassCompletion(stylesheets: Stylesheet[], attributeContext: AttributeContext): CompletionList | null;
|
||||
/**
|
||||
* incomplete see
|
||||
* https://github.com/microsoft/vscode-css-languageservice/blob/master/src/parser/cssNodes.ts#L14
|
||||
* The enum is not exported. we have to update this whenever it changes
|
||||
*/
|
||||
export declare enum NodeType {
|
||||
ClassSelector = 14,
|
||||
IdentifierSelector = 15
|
||||
}
|
||||
export type CSSNode = {
|
||||
type: number;
|
||||
children: CSSNode[] | undefined;
|
||||
getText(): string;
|
||||
};
|
||||
export declare function collectSelectors(stylesheets: CSSNode[], type: number): CompletionItem[];
|
||||
57
node_modules/@astrojs/language-server/dist/plugins/css/features/getIdClassCompletions.js
generated
vendored
Normal file
57
node_modules/@astrojs/language-server/dist/plugins/css/features/getIdClassCompletions.js
generated
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.collectSelectors = exports.NodeType = exports.getIdClassCompletion = void 0;
|
||||
const vscode_languageserver_1 = require("vscode-languageserver");
|
||||
function getIdClassCompletion(stylesheets, attributeContext) {
|
||||
const collectingType = getCollectingType(attributeContext);
|
||||
if (!collectingType) {
|
||||
return null;
|
||||
}
|
||||
const items = collectSelectors(stylesheets, collectingType);
|
||||
return vscode_languageserver_1.CompletionList.create(items);
|
||||
}
|
||||
exports.getIdClassCompletion = getIdClassCompletion;
|
||||
function getCollectingType(attributeContext) {
|
||||
if (attributeContext.inValue) {
|
||||
if (attributeContext.name === 'class') {
|
||||
return NodeType.ClassSelector;
|
||||
}
|
||||
if (attributeContext.name === 'id') {
|
||||
return NodeType.IdentifierSelector;
|
||||
}
|
||||
}
|
||||
else if (attributeContext.name.startsWith('class:')) {
|
||||
return NodeType.ClassSelector;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* incomplete see
|
||||
* https://github.com/microsoft/vscode-css-languageservice/blob/master/src/parser/cssNodes.ts#L14
|
||||
* The enum is not exported. we have to update this whenever it changes
|
||||
*/
|
||||
var NodeType;
|
||||
(function (NodeType) {
|
||||
NodeType[NodeType["ClassSelector"] = 14] = "ClassSelector";
|
||||
NodeType[NodeType["IdentifierSelector"] = 15] = "IdentifierSelector";
|
||||
})(NodeType = exports.NodeType || (exports.NodeType = {}));
|
||||
function collectSelectors(stylesheets, type) {
|
||||
const result = [];
|
||||
stylesheets.forEach((stylesheet) => {
|
||||
walk(stylesheet, (node) => {
|
||||
if (node.type === type) {
|
||||
result.push(node);
|
||||
}
|
||||
});
|
||||
});
|
||||
return result.map((node) => ({
|
||||
label: node.getText().substring(1),
|
||||
kind: vscode_languageserver_1.CompletionItemKind.Keyword,
|
||||
}));
|
||||
}
|
||||
exports.collectSelectors = collectSelectors;
|
||||
function walk(node, callback) {
|
||||
callback(node);
|
||||
if (node.children) {
|
||||
node.children.forEach((childrenNode) => walk(childrenNode, callback));
|
||||
}
|
||||
}
|
||||
3
node_modules/@astrojs/language-server/dist/plugins/css/language-service.d.ts
generated
vendored
Normal file
3
node_modules/@astrojs/language-server/dist/plugins/css/language-service.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import { LanguageService } from 'vscode-css-languageservice';
|
||||
export declare function getLanguage(kind?: string): "css" | "less" | "scss";
|
||||
export declare function getLanguageService(kind?: string): LanguageService;
|
||||
47
node_modules/@astrojs/language-server/dist/plugins/css/language-service.js
generated
vendored
Normal file
47
node_modules/@astrojs/language-server/dist/plugins/css/language-service.js
generated
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getLanguageService = exports.getLanguage = void 0;
|
||||
const vscode_css_languageservice_1 = require("vscode-css-languageservice");
|
||||
const astro_selectors_1 = require("./features/astro-selectors");
|
||||
const customDataProvider = {
|
||||
providePseudoClasses() {
|
||||
return astro_selectors_1.pseudoClass;
|
||||
},
|
||||
provideProperties() {
|
||||
return [];
|
||||
},
|
||||
provideAtDirectives() {
|
||||
return [];
|
||||
},
|
||||
providePseudoElements() {
|
||||
return [];
|
||||
},
|
||||
};
|
||||
const [css, scss, less] = [vscode_css_languageservice_1.getCSSLanguageService, vscode_css_languageservice_1.getSCSSLanguageService, vscode_css_languageservice_1.getLESSLanguageService].map((getService) => getService({
|
||||
customDataProviders: [customDataProvider],
|
||||
}));
|
||||
const langs = {
|
||||
css,
|
||||
scss,
|
||||
less,
|
||||
};
|
||||
function getLanguage(kind) {
|
||||
switch (kind) {
|
||||
case 'scss':
|
||||
case 'text/scss':
|
||||
return 'scss';
|
||||
case 'less':
|
||||
case 'text/less':
|
||||
return 'less';
|
||||
case 'css':
|
||||
case 'text/css':
|
||||
default:
|
||||
return 'css';
|
||||
}
|
||||
}
|
||||
exports.getLanguage = getLanguage;
|
||||
function getLanguageService(kind) {
|
||||
const lang = getLanguage(kind);
|
||||
return langs[lang];
|
||||
}
|
||||
exports.getLanguageService = getLanguageService;
|
||||
Loading…
Add table
Add a link
Reference in a new issue