Skip to content

Commit

Permalink
move the svelte highlight to ts using ast returned by svelte2tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlyu123 committed Jan 17, 2024
1 parent 0ec1b8e commit fc193fd
Show file tree
Hide file tree
Showing 9 changed files with 424 additions and 408 deletions.
9 changes: 9 additions & 0 deletions packages/language-server/src/lib/documents/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Position, Range } from 'vscode-languageserver';
import { Node, HTMLDocument } from 'vscode-html-languageservice';
import * as path from 'path';
import { parseHtml } from './parseHtml';
import { Document } from './Document';

export interface TagInformation {
content: string;
Expand Down Expand Up @@ -442,3 +443,11 @@ export function isInsideMoustacheTag(html: string, tagStart: number | null, posi
return charactersInNode.lastIndexOf('{') > charactersInNode.lastIndexOf('}');
}
}

export function inStyleOrScript(document: Document, position: Position) {
return (
isInTag(position, document.styleInfo) ||
isInTag(position, document.scriptInfo) ||
isInTag(position, document.moduleScriptInfo)
);
}
6 changes: 3 additions & 3 deletions packages/language-server/src/ls-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const defaultLSConfig: LSConfig = {
codeActions: { enable: true },
selectionRange: { enable: true },
signatureHelp: { enable: true },
semanticTokens: { enable: true },
semanticTokens: { enable: true }
},
css: {
enable: true,
Expand All @@ -32,15 +32,15 @@ const defaultLSConfig: LSConfig = {
documentColors: { enable: true },
colorPresentations: { enable: true },
documentSymbols: { enable: true },
selectionRange: { enable: true },
selectionRange: { enable: true }
},
html: {
enable: true,
hover: { enable: true },
completions: { enable: true, emmet: true },
tagComplete: { enable: true },
documentSymbols: { enable: true },
linkedEditing: { enable: true },
linkedEditing: { enable: true }
},
svelte: {
enable: true,
Expand Down
4 changes: 0 additions & 4 deletions packages/language-server/src/plugins/css/CSSPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,6 @@ export class CSSPlugin
}

findDocumentHighlight(document: Document, position: Position): DocumentHighlight[] | null {
if (!document.styleInfo) {
return [];
}

const cssDocument = this.getCSSDoc(document);
if (cssDocument.isInGenerated(position)) {
return this.findDocumentHighlightInternal(cssDocument, position);
Expand Down
4 changes: 4 additions & 0 deletions packages/language-server/src/plugins/html/HTMLPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ export class HTMLPlugin
return null;
}

const node = html.findNodeAt(document.offsetAt(position));
if (possiblyComponent(node)) {
return null;
}
const result = this.lang.findDocumentHighlights(document, position, html);

if (!result.length) {
Expand Down
15 changes: 1 addition & 14 deletions packages/language-server/src/plugins/svelte/SveltePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
CompletionContext,
CompletionList,
Diagnostic,
DocumentHighlight,
FormattingOptions,
Hover,
Position,
Expand All @@ -25,7 +24,6 @@ import {
CodeActionsProvider,
CompletionsProvider,
DiagnosticsProvider,
DocumentHighlightProvider,
FormattingProvider,
HoverProvider,
SelectionRangeProvider
Expand All @@ -36,7 +34,6 @@ import { getDiagnostics } from './features/getDiagnostics';
import { getHoverInfo } from './features/getHoverInfo';
import { getSelectionRange } from './features/getSelectionRanges';
import { SvelteCompileResult, SvelteDocument } from './SvelteDocument';
import { getDocumentHighlight } from './features/getDocumentHighlight';

export class SveltePlugin
implements
Expand All @@ -45,8 +42,7 @@ export class SveltePlugin
CompletionsProvider,
HoverProvider,
CodeActionsProvider,
SelectionRangeProvider,
DocumentHighlightProvider
SelectionRangeProvider
{
__name = 'svelte';
private docManager = new Map<Document, SvelteDocument>();
Expand Down Expand Up @@ -317,15 +313,6 @@ export class SveltePlugin
return getSelectionRange(svelteDoc, position);
}

async findDocumentHighlight(
document: Document,
position: Position
): Promise<DocumentHighlight[] | null> {
const svelteDoc = await this.getSvelteDoc(document);

return getDocumentHighlight(svelteDoc, position);
}

private featureEnabled(feature: keyof LSSvelteConfig) {
return (
this.configManager.enabled('svelte.enable') &&
Expand Down

This file was deleted.

Loading

0 comments on commit fc193fd

Please sign in to comment.