summaryrefslogtreecommitdiff
path: root/tools/astro-languageserver/src/plugins/css/CSSDocument.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tools/astro-languageserver/src/plugins/css/CSSDocument.ts')
-rw-r--r--tools/astro-languageserver/src/plugins/css/CSSDocument.ts144
1 files changed, 72 insertions, 72 deletions
diff --git a/tools/astro-languageserver/src/plugins/css/CSSDocument.ts b/tools/astro-languageserver/src/plugins/css/CSSDocument.ts
index 90b28352c..9f1839678 100644
--- a/tools/astro-languageserver/src/plugins/css/CSSDocument.ts
+++ b/tools/astro-languageserver/src/plugins/css/CSSDocument.ts
@@ -4,92 +4,92 @@ import { getLanguageService } from './service';
import { Document, DocumentMapper, ReadableDocument, TagInformation } from '../../core/documents/index';
export interface CSSDocumentBase extends DocumentMapper, TextDocument {
- languageId: string;
- stylesheet: Stylesheet;
+ languageId: string;
+ stylesheet: Stylesheet;
}
export class CSSDocument extends ReadableDocument implements DocumentMapper {
- private styleInfo: Pick<TagInformation, 'attributes' | 'start' | 'end'>;
- readonly version = this.parent.version;
+ private styleInfo: Pick<TagInformation, 'attributes' | 'start' | 'end'>;
+ readonly version = this.parent.version;
- public stylesheet: Stylesheet;
- public languageId: string;
+ public stylesheet: Stylesheet;
+ public languageId: string;
- constructor(private parent: Document) {
- super();
+ constructor(private parent: Document) {
+ super();
- if (this.parent.styleInfo) {
- this.styleInfo = this.parent.styleInfo;
- } else {
- this.styleInfo = {
- attributes: {},
- start: -1,
- end: -1
- };
- }
-
- this.languageId = this.language;
- this.stylesheet = getLanguageService(this.language).parseStylesheet(this);
+ if (this.parent.styleInfo) {
+ this.styleInfo = this.parent.styleInfo;
+ } else {
+ this.styleInfo = {
+ attributes: {},
+ start: -1,
+ end: -1,
+ };
}
- /**
- * Get the fragment position relative to the parent
- * @param pos Position in fragment
- */
- getOriginalPosition(pos: Position): Position {
- const parentOffset = this.styleInfo.start + this.offsetAt(pos);
- return this.parent.positionAt(parentOffset);
- }
+ this.languageId = this.language;
+ this.stylesheet = getLanguageService(this.language).parseStylesheet(this);
+ }
- /**
- * Get the position relative to the start of the fragment
- * @param pos Position in parent
- */
- getGeneratedPosition(pos: Position): Position {
- const fragmentOffset = this.parent.offsetAt(pos) - this.styleInfo.start;
- return this.positionAt(fragmentOffset);
- }
+ /**
+ * Get the fragment position relative to the parent
+ * @param pos Position in fragment
+ */
+ getOriginalPosition(pos: Position): Position {
+ const parentOffset = this.styleInfo.start + this.offsetAt(pos);
+ return this.parent.positionAt(parentOffset);
+ }
- /**
- * Returns true if the given parent position is inside of this fragment
- * @param pos Position in parent
- */
- isInGenerated(pos: Position): boolean {
- const offset = this.parent.offsetAt(pos);
- return offset >= this.styleInfo.start && offset <= this.styleInfo.end;
- }
+ /**
+ * Get the position relative to the start of the fragment
+ * @param pos Position in parent
+ */
+ getGeneratedPosition(pos: Position): Position {
+ const fragmentOffset = this.parent.offsetAt(pos) - this.styleInfo.start;
+ return this.positionAt(fragmentOffset);
+ }
- /**
- * Get the fragment text from the parent
- */
- getText(): string {
- return this.parent.getText().slice(this.styleInfo.start, this.styleInfo.end);
- }
+ /**
+ * Returns true if the given parent position is inside of this fragment
+ * @param pos Position in parent
+ */
+ isInGenerated(pos: Position): boolean {
+ const offset = this.parent.offsetAt(pos);
+ return offset >= this.styleInfo.start && offset <= this.styleInfo.end;
+ }
- /**
- * Returns the length of the fragment as calculated from the start and end positon
- */
- getTextLength(): number {
- return this.styleInfo.end - this.styleInfo.start;
- }
+ /**
+ * Get the fragment text from the parent
+ */
+ getText(): string {
+ return this.parent.getText().slice(this.styleInfo.start, this.styleInfo.end);
+ }
- /**
- * Return the parent file path
- */
- getFilePath(): string | null {
- return this.parent.getFilePath();
- }
+ /**
+ * Returns the length of the fragment as calculated from the start and end positon
+ */
+ getTextLength(): number {
+ return this.styleInfo.end - this.styleInfo.start;
+ }
- getURL() {
- return this.parent.getURL();
- }
+ /**
+ * Return the parent file path
+ */
+ getFilePath(): string | null {
+ return this.parent.getFilePath();
+ }
- getAttributes() {
- return this.styleInfo.attributes;
- }
+ getURL() {
+ return this.parent.getURL();
+ }
- private get language() {
- const attrs = this.getAttributes();
- return attrs.lang || attrs.type || 'css';
- }
+ getAttributes() {
+ return this.styleInfo.attributes;
+ }
+
+ private get language() {
+ const attrs = this.getAttributes();
+ return attrs.lang || attrs.type || 'css';
+ }
}