🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
33
node_modules/@astrojs/language-server/dist/plugins/html/HTMLPlugin.d.ts
generated
vendored
Normal file
33
node_modules/@astrojs/language-server/dist/plugins/html/HTMLPlugin.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { CompletionList, FoldingRange, Hover, LinkedEditingRanges, Position, Range, SymbolInformation, WorkspaceEdit } from 'vscode-languageserver';
|
||||
import type { ConfigManager } from '../../core/config/ConfigManager';
|
||||
import type { AstroDocument } from '../../core/documents/AstroDocument';
|
||||
import type { Plugin } from '../interfaces';
|
||||
export declare class HTMLPlugin implements Plugin {
|
||||
__name: string;
|
||||
private lang;
|
||||
private attributeOnlyLang;
|
||||
private componentLang;
|
||||
private styleScriptTemplate;
|
||||
private configManager;
|
||||
constructor(configManager: ConfigManager);
|
||||
doHover(document: AstroDocument, position: Position): Promise<Hover | null>;
|
||||
/**
|
||||
* Get HTML completions
|
||||
*/
|
||||
getCompletions(document: AstroDocument, position: Position): Promise<CompletionList | null>;
|
||||
getFoldingRanges(document: AstroDocument): FoldingRange[] | null;
|
||||
getLinkedEditingRanges(document: AstroDocument, position: Position): LinkedEditingRanges | null;
|
||||
doTagComplete(document: AstroDocument, position: Position): Promise<string | null>;
|
||||
prepareRename(document: AstroDocument, position: Position): Range | null;
|
||||
rename(document: AstroDocument, position: Position, newName: string): WorkspaceEdit | null;
|
||||
getDocumentSymbols(document: AstroDocument): Promise<SymbolInformation[]>;
|
||||
/**
|
||||
* Get lang completions for style tags (ex: `<style lang="scss">`)
|
||||
*/
|
||||
private getLangCompletions;
|
||||
/**
|
||||
* Returns true if rename happens at the tag name, not anywhere inbetween.
|
||||
*/
|
||||
private isRenameAtTag;
|
||||
private featureEnabled;
|
||||
}
|
||||
198
node_modules/@astrojs/language-server/dist/plugins/html/HTMLPlugin.js
generated
vendored
Normal file
198
node_modules/@astrojs/language-server/dist/plugins/html/HTMLPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.HTMLPlugin = void 0;
|
||||
const emmet_helper_1 = require("@vscode/emmet-helper");
|
||||
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
||||
const vscode_languageserver_1 = require("vscode-languageserver");
|
||||
const utils_1 = require("../../core/documents/utils");
|
||||
const astro_attributes_1 = require("./features/astro-attributes");
|
||||
const utils_2 = require("./utils");
|
||||
class HTMLPlugin {
|
||||
constructor(configManager) {
|
||||
this.__name = 'html';
|
||||
this.lang = (0, vscode_html_languageservice_1.getLanguageService)({
|
||||
customDataProviders: [astro_attributes_1.astroAttributes, astro_attributes_1.astroElements, astro_attributes_1.classListAttribute],
|
||||
});
|
||||
this.attributeOnlyLang = (0, vscode_html_languageservice_1.getLanguageService)({
|
||||
customDataProviders: [astro_attributes_1.astroAttributes],
|
||||
useDefaultDataProvider: false,
|
||||
});
|
||||
this.componentLang = (0, vscode_html_languageservice_1.getLanguageService)({
|
||||
customDataProviders: [astro_attributes_1.astroAttributes, astro_attributes_1.astroDirectives],
|
||||
useDefaultDataProvider: false,
|
||||
});
|
||||
this.styleScriptTemplate = new Set(['style']);
|
||||
this.configManager = configManager;
|
||||
}
|
||||
async doHover(document, position) {
|
||||
if (!(await this.featureEnabled(document, 'hover'))) {
|
||||
return null;
|
||||
}
|
||||
const html = document.html;
|
||||
if (!html) {
|
||||
return null;
|
||||
}
|
||||
const node = html.findNodeAt(document.offsetAt(position));
|
||||
if (!node) {
|
||||
return null;
|
||||
}
|
||||
// If the node we're hovering on is a component, instead only provide astro-specific hover info
|
||||
if ((0, utils_1.isPossibleComponent)(node) && node.tag !== 'Fragment') {
|
||||
return this.componentLang.doHover(document, position, html);
|
||||
}
|
||||
return this.lang.doHover(document, position, html);
|
||||
}
|
||||
/**
|
||||
* Get HTML completions
|
||||
*/
|
||||
async getCompletions(document, position) {
|
||||
if (!(await this.featureEnabled(document, 'completions'))) {
|
||||
return null;
|
||||
}
|
||||
const html = document.html;
|
||||
const offset = document.offsetAt(position);
|
||||
if (!html ||
|
||||
(0, utils_1.isInsideFrontmatter)(document.getText(), offset) ||
|
||||
(0, utils_1.isInsideExpression)(document.getText(), html.findNodeAt(offset).start, offset)) {
|
||||
return null;
|
||||
}
|
||||
// Get Emmet completions
|
||||
let emmetResults = {
|
||||
isIncomplete: true,
|
||||
items: [],
|
||||
};
|
||||
const emmetConfig = await this.configManager.getEmmetConfig(document);
|
||||
const extensionConfig = (await this.configManager.getConfig('astro', document.uri)) ?? {};
|
||||
if (extensionConfig?.html?.completions?.emmet ?? true) {
|
||||
this.lang.setCompletionParticipants([
|
||||
{
|
||||
onHtmlContent: () => (emmetResults = (0, emmet_helper_1.doComplete)(document, position, 'html', emmetConfig) || emmetResults),
|
||||
},
|
||||
]);
|
||||
}
|
||||
// If we're in a component starting tag, we do not want HTML language completions
|
||||
// as HTML attributes are not valid for components
|
||||
const inComponentTag = (0, utils_1.isInComponentStartTag)(html, offset);
|
||||
const inTagName = (0, utils_1.isInTagName)(html, offset);
|
||||
const results = inComponentTag && !inTagName
|
||||
? (0, utils_2.removeDataAttrCompletion)(this.attributeOnlyLang.doComplete(document, position, html).items)
|
||||
: this.lang.doComplete(document, position, html).items.filter(isNoAddedTagWithNoDocumentation);
|
||||
const langCompletions = inComponentTag ? [] : this.getLangCompletions(results);
|
||||
return vscode_languageserver_1.CompletionList.create([...results, ...langCompletions, ...emmetResults.items],
|
||||
// Emmet completions change on every keystroke, so they are never complete
|
||||
emmetResults.items.length > 0);
|
||||
// Filter script and style completions with no documentation to prevent duplicates
|
||||
// due to our added definitions for those tags
|
||||
function isNoAddedTagWithNoDocumentation(item) {
|
||||
return !(['script', 'style'].includes(item.label) && item.documentation === undefined);
|
||||
}
|
||||
}
|
||||
getFoldingRanges(document) {
|
||||
const html = document.html;
|
||||
if (!html) {
|
||||
return null;
|
||||
}
|
||||
return this.lang.getFoldingRanges(document);
|
||||
}
|
||||
getLinkedEditingRanges(document, position) {
|
||||
const html = document.html;
|
||||
if (!html) {
|
||||
return null;
|
||||
}
|
||||
const ranges = this.lang.findLinkedEditingRanges(document, position, html);
|
||||
if (!ranges) {
|
||||
return null;
|
||||
}
|
||||
return { ranges };
|
||||
}
|
||||
async doTagComplete(document, position) {
|
||||
if (!(await this.featureEnabled(document, 'tagComplete'))) {
|
||||
return null;
|
||||
}
|
||||
const html = document.html;
|
||||
const offset = document.offsetAt(position);
|
||||
if (!html ||
|
||||
(0, utils_1.isInsideFrontmatter)(document.getText(), offset) ||
|
||||
(0, utils_1.isInsideExpression)(document.getText(), html.findNodeAt(offset).start, offset)) {
|
||||
return null;
|
||||
}
|
||||
return this.lang.doTagComplete(document, position, html);
|
||||
}
|
||||
prepareRename(document, position) {
|
||||
const html = document.html;
|
||||
const offset = document.offsetAt(position);
|
||||
const node = html.findNodeAt(offset);
|
||||
if (!node || (0, utils_1.isPossibleComponent)(node) || !node.tag || !this.isRenameAtTag(node, offset)) {
|
||||
return null;
|
||||
}
|
||||
const tagNameStart = node.start + '<'.length;
|
||||
return vscode_languageserver_1.Range.create(document.positionAt(tagNameStart), document.positionAt(tagNameStart + node.tag.length));
|
||||
}
|
||||
rename(document, position, newName) {
|
||||
const html = document.html;
|
||||
const offset = document.offsetAt(position);
|
||||
if (!html || (0, utils_1.isInsideFrontmatter)(document.getText(), offset)) {
|
||||
return null;
|
||||
}
|
||||
const node = html.findNodeAt(offset);
|
||||
// The TypeScript plugin handles renaming for components
|
||||
if (!node || (0, utils_1.isPossibleComponent)(node) || !this.isRenameAtTag(node, offset)) {
|
||||
return null;
|
||||
}
|
||||
return this.lang.doRename(document, position, newName, html);
|
||||
}
|
||||
async getDocumentSymbols(document) {
|
||||
if (!(await this.featureEnabled(document, 'documentSymbols'))) {
|
||||
return [];
|
||||
}
|
||||
const html = document.html;
|
||||
if (!html) {
|
||||
return [];
|
||||
}
|
||||
return this.lang.findDocumentSymbols(document, html);
|
||||
}
|
||||
/**
|
||||
* Get lang completions for style tags (ex: `<style lang="scss">`)
|
||||
*/
|
||||
getLangCompletions(completions) {
|
||||
const styleScriptTemplateCompletions = completions.filter((completion) => completion.kind === vscode_languageserver_1.CompletionItemKind.Property && this.styleScriptTemplate.has(completion.label));
|
||||
const langCompletions = [];
|
||||
addLangCompletion('style', ['scss', 'sass', 'less', 'styl', 'stylus']);
|
||||
return langCompletions;
|
||||
/** Add language completions */
|
||||
function addLangCompletion(tag, languages) {
|
||||
const existingCompletion = styleScriptTemplateCompletions.find((completion) => completion.label === tag);
|
||||
if (!existingCompletion) {
|
||||
return;
|
||||
}
|
||||
languages.forEach((lang) => langCompletions.push({
|
||||
...existingCompletion,
|
||||
label: `${tag} (lang="${lang}")`,
|
||||
insertText: existingCompletion.insertText && `${existingCompletion.insertText} lang="${lang}"`,
|
||||
textEdit: existingCompletion.textEdit && vscode_languageserver_1.TextEdit.is(existingCompletion.textEdit)
|
||||
? {
|
||||
range: existingCompletion.textEdit.range,
|
||||
newText: `${existingCompletion.textEdit.newText} lang="${lang}"`,
|
||||
}
|
||||
: undefined,
|
||||
}));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns true if rename happens at the tag name, not anywhere inbetween.
|
||||
*/
|
||||
isRenameAtTag(node, offset) {
|
||||
if (!node.tag) {
|
||||
return false;
|
||||
}
|
||||
const startTagNameEnd = node.start + `<${node.tag}`.length;
|
||||
const isAtStartTag = offset > node.start && offset <= startTagNameEnd;
|
||||
const isAtEndTag = node.endTagStart !== undefined && offset >= node.endTagStart && offset < node.end;
|
||||
return isAtStartTag || isAtEndTag;
|
||||
}
|
||||
async featureEnabled(document, feature) {
|
||||
return ((await this.configManager.isEnabled(document, 'html')) &&
|
||||
(await this.configManager.isEnabled(document, 'html', feature)));
|
||||
}
|
||||
}
|
||||
exports.HTMLPlugin = HTMLPlugin;
|
||||
4
node_modules/@astrojs/language-server/dist/plugins/html/features/astro-attributes.d.ts
generated
vendored
Normal file
4
node_modules/@astrojs/language-server/dist/plugins/html/features/astro-attributes.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
export declare const classListAttribute: import("vscode-html-languageservice").IHTMLDataProvider;
|
||||
export declare const astroElements: import("vscode-html-languageservice").IHTMLDataProvider;
|
||||
export declare const astroAttributes: import("vscode-html-languageservice").IHTMLDataProvider;
|
||||
export declare const astroDirectives: import("vscode-html-languageservice").IHTMLDataProvider;
|
||||
235
node_modules/@astrojs/language-server/dist/plugins/html/features/astro-attributes.js
generated
vendored
Normal file
235
node_modules/@astrojs/language-server/dist/plugins/html/features/astro-attributes.js
generated
vendored
Normal file
|
|
@ -0,0 +1,235 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.astroDirectives = exports.astroAttributes = exports.astroElements = exports.classListAttribute = void 0;
|
||||
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
||||
const defaultProvider = (0, vscode_html_languageservice_1.getDefaultHTMLDataProvider)();
|
||||
const slotAttr = defaultProvider.provideAttributes('div').find((attr) => attr.name === 'slot');
|
||||
exports.classListAttribute = (0, vscode_html_languageservice_1.newHTMLDataProvider)('class-list', {
|
||||
version: 1,
|
||||
globalAttributes: [
|
||||
{
|
||||
name: 'class:list',
|
||||
description: 'Utility to provide a list of class',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/reference/directives-reference/#classlist',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
exports.astroElements = (0, vscode_html_languageservice_1.newHTMLDataProvider)('astro-elements', {
|
||||
version: 1,
|
||||
tags: [
|
||||
{
|
||||
name: 'slot',
|
||||
description: 'The slot element is a placeholder for external HTML content, allowing you to inject (or “slot”) child elements from other files into your component template.',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/core-concepts/astro-components/#slots',
|
||||
},
|
||||
],
|
||||
attributes: [
|
||||
{
|
||||
name: 'name',
|
||||
description: 'The name attribute allows you to pass only HTML elements with the corresponding slot name into a slot’s location.',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/core-concepts/astro-components/#named-slots',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'script',
|
||||
attributes: [
|
||||
{
|
||||
// The VS Code tag definitions does not provide a description for the deprecated `charset` attribute on script tags
|
||||
// Which mean that since we get no hover info for this, we instead get JSX hover info. So we'll just specify a description ourselves for this specific case
|
||||
name: 'charset',
|
||||
description: "**Deprecated**\n\nIt's unnecessary to specify the charset attribute, because documents must use UTF-8, and the script element inherits its character encoding from the document.",
|
||||
},
|
||||
{
|
||||
name: 'define:vars',
|
||||
description: 'Passes serializable server-side variables into a client-side script element',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/reference/directives-reference/#definevars',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'hoist',
|
||||
description: '**Deprecated in Astro >= 0.26.0**\n\nBuilds, optimizes, and bundles your script with the other JavaScript on the page',
|
||||
valueSet: 'v',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/core-concepts/astro-components/#using-hoisted-scripts',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'is:inline',
|
||||
description: 'Leave a script tag inline in the page template. No processing will be done on its content',
|
||||
valueSet: 'v',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/reference/directives-reference/#isinline',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'style',
|
||||
attributes: [
|
||||
{
|
||||
name: 'define:vars',
|
||||
description: 'Passes serializable server-side variables into a client-side style element',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/reference/directives-reference/#definevars',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'global',
|
||||
description: '**Deprecated in favor of `is:global` in >= Astro 0.26.0**\n\nOpts-out of automatic CSS scoping, all contents will be available globally',
|
||||
valueSet: 'v',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/reference/directives-reference/#isglobal',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'is:global',
|
||||
description: 'Opts-out of automatic CSS scoping, all contents will be available globally',
|
||||
valueSet: 'v',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/reference/directives-reference/#isglobal',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'is:inline',
|
||||
description: 'Leave a style tag inline in the page template. No processing will be done on its content',
|
||||
valueSet: 'v',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/reference/directives-reference/#isinline',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)('astro-attributes', {
|
||||
version: 1,
|
||||
globalAttributes: [
|
||||
{
|
||||
name: 'set:html',
|
||||
description: 'Inject unescaped HTML into this tag',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/reference/directives-reference/#sethtml',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'set:text',
|
||||
description: 'Inject escaped text into this tag',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/reference/directives-reference/#settext',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'is:raw',
|
||||
description: 'Instructs the Astro compiler to treat any children of this element as text',
|
||||
valueSet: 'v',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/reference/directives-reference/#israw',
|
||||
},
|
||||
],
|
||||
},
|
||||
slotAttr,
|
||||
],
|
||||
});
|
||||
exports.astroDirectives = (0, vscode_html_languageservice_1.newHTMLDataProvider)('astro-directives', {
|
||||
version: 1,
|
||||
globalAttributes: [
|
||||
{
|
||||
name: 'client:load',
|
||||
description: 'Start importing the component JS at page load. Hydrate the component when import completes.',
|
||||
valueSet: 'v',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/reference/directives-reference/#clientload',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'client:idle',
|
||||
description: 'Start importing the component JS as soon as main thread is free (uses requestIdleCallback()). Hydrate the component when import completes.',
|
||||
valueSet: 'v',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/reference/directives-reference/#clientidle',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'client:visible',
|
||||
description: 'Start importing the component JS as soon as the element enters the viewport (uses IntersectionObserver). Hydrate the component when import completes. Useful for content lower down on the page.',
|
||||
valueSet: 'v',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/reference/directives-reference/#clientvisible',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'client:media',
|
||||
description: 'Start importing the component JS as soon as the browser matches the given media query (uses matchMedia). Hydrate the component when import completes. Useful for sidebar toggles, or other elements that should only display on mobile or desktop devices.',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/reference/directives-reference/#clientmedia',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'client:only',
|
||||
description: 'Start importing the component JS at page load and hydrate when the import completes, similar to client:load. The component will be skipped at build time, useful for components that are entirely dependent on client-side APIs. This is best avoided unless absolutely needed, in most cases it is best to render placeholder content on the server and delay any browser API calls until the component hydrates in the browser.',
|
||||
valueSet: 'v',
|
||||
references: [
|
||||
{
|
||||
name: 'Astro reference',
|
||||
url: 'https://docs.astro.build/en/reference/directives-reference/#clientonly',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
6
node_modules/@astrojs/language-server/dist/plugins/html/utils.d.ts
generated
vendored
Normal file
6
node_modules/@astrojs/language-server/dist/plugins/html/utils.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import type { CompletionItem } from 'vscode-languageserver-types';
|
||||
/**
|
||||
* The VS Code HTML language service provides a completion for data attributes that is independent from
|
||||
* data providers, which mean that you can't disable it, so this function removes them from completions
|
||||
*/
|
||||
export declare function removeDataAttrCompletion(items: CompletionItem[]): CompletionItem[];
|
||||
11
node_modules/@astrojs/language-server/dist/plugins/html/utils.js
generated
vendored
Normal file
11
node_modules/@astrojs/language-server/dist/plugins/html/utils.js
generated
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.removeDataAttrCompletion = void 0;
|
||||
/**
|
||||
* The VS Code HTML language service provides a completion for data attributes that is independent from
|
||||
* data providers, which mean that you can't disable it, so this function removes them from completions
|
||||
*/
|
||||
function removeDataAttrCompletion(items) {
|
||||
return items.filter((item) => !item.label.startsWith('data-'));
|
||||
}
|
||||
exports.removeDataAttrCompletion = removeDataAttrCompletion;
|
||||
Loading…
Add table
Add a link
Reference in a new issue