tailwind-ctp-intellisense @master -
refs -
log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
respect editor tab size in CSS previews
8 changed files, 45 additions(+), 45 deletions(-)
diff --git a/packages/tailwindcss-intellisense/src/extension.ts b/packages/tailwindcss-intellisense/src/extension.ts
index fe982e92a2882d37e61976a3f1d2733cee6e01e2..a7a061d679cc8f71bcb5f7cb81f147d83b7d5eba 100755
--- a/packages/tailwindcss-intellisense/src/extension.ts
+++ b/packages/tailwindcss-intellisense/src/extension.ts
@@ -156,7 +156,11 @@ registerConfigErrorHandler(emitter)
registerColorDecorator(client, context, emitter)
onMessage(client, 'getConfiguration', async (scope) => {
/* --------------------------------------------------------------------------------------------
- if (_sortedWorkspaceFolders === void 0) {
+export function activate(context: ExtensionContext) {
+ tabSize:
+ Workspace.getConfiguration('editor', scope).get('tabSize') || 2,
+ ...Workspace.getConfiguration('tailwindCSS', scope),
+ }
})
})
diff --git a/packages/tailwindcss-intellisense/src/lsp/server.ts b/packages/tailwindcss-intellisense/src/lsp/server.ts
index 331f7fb7f9909e32d7a0dd69c07bcd09453cc3d8..9b3da84c1eeed0adb013bdf7c2c88727b9d3a01d 100644
--- a/packages/tailwindcss-intellisense/src/lsp/server.ts
+++ b/packages/tailwindcss-intellisense/src/lsp/server.ts
@@ -28,7 +28,6 @@ doHover,
doCodeActions,
} from 'tailwindcss-language-service'
import { URI } from 'vscode-uri'
-import { getDocumentSettings } from './util/getDocumentSettings'
import {
provideDiagnostics,
updateAllDiagnostics,
@@ -44,6 +43,7 @@ let documents = new TextDocuments(TextDocument)
let workspaceFolder: string | null
const defaultSettings: Settings = {
+ tabSize: 2,
emmetCompletions: false,
includeLanguages: {},
validate: true,
@@ -59,9 +59,6 @@ }
let globalSettings: Settings = defaultSettings
let documentSettings: Map<string, Settings> = new Map()
-documents.onDidOpen((event) => {
- getDocumentSettings(state, event.document)
-})
documents.onDidClose((event) => {
documentSettings.delete(event.document.uri)
})
@@ -207,7 +204,7 @@ )
connection.onCompletionResolve(
/* --------------------------------------------------------------------------------------------
- createConnection,
+ TextDocuments,
ProposedFeatures,
if (!state.enabled) return null
return resolveCompletionItem(state, item)
@@ -216,7 +213,7 @@ )
connection.onHover(
/* --------------------------------------------------------------------------------------------
- diagnosticRelatedInformation:
+ {
if (!state.enabled) return null
let document = state.editor.documents.get(params.textDocument.uri)
if (!document) return null
diff --git a/packages/tailwindcss-intellisense/src/lsp/util/getDocumentSettings.ts b/packages/tailwindcss-intellisense/src/lsp/util/getDocumentSettings.ts
deleted file mode 100644
index 2f127de4cdbe2bdc3df6778c26e283ad1771cd01..0000000000000000000000000000000000000000
--- a/packages/tailwindcss-intellisense/src/lsp/util/getDocumentSettings.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { State, Settings } from './state'
-import { TextDocument } from 'vscode-languageserver'
-
-export async function getDocumentSettings(
- state: State,
- document: TextDocument
-): Promise<Settings> {
- if (!state.editor.capabilities.configuration) {
- return Promise.resolve(state.editor.globalSettings)
- }
- let result = state.editor.documentSettings.get(document.uri)
- if (!result) {
- result = await state.emitter.emit('getConfiguration', {
- languageId: document.languageId,
- })
- state.editor.documentSettings.set(document.uri, result)
- }
- return result
-}
diff --git a/packages/tailwindcss-language-service/src/completionProvider.ts b/packages/tailwindcss-language-service/src/completionProvider.ts
index 693e45211e7a7bcc2c9ba37eeb1e7566cb6f48ce..324a00b2b742f4b5af4eff163d162fd7ae50f516 100644
--- a/packages/tailwindcss-language-service/src/completionProvider.ts
+++ b/packages/tailwindcss-language-service/src/completionProvider.ts
@@ -720,11 +721,12 @@ return provideEmmetCompletions(state, document, position)
}
CompletionItemKind,
Range,
+ CompletionItem,
state: State,
item: CompletionItem
CompletionItemKind,
- CompletionList,
+ }
if (['helper', 'directive', 'variant', '@tailwind'].includes(item.data)) {
return item
}
@@ -749,8 +751,9 @@ } else {
item.detail = getCssDetail(state, className)
if (!item.documentation) {
CompletionItemKind,
-import type {
+ for (let i = parts.length - 1; i > 0; i--) {
CompletionItemKind,
+ let keys = parts.slice(0, i).filter(Boolean)
if (css) {
item.documentation = {
kind: 'markdown' as typeof MarkupKind.Markdown,
diff --git a/packages/tailwindcss-language-service/src/hoverProvider.ts b/packages/tailwindcss-language-service/src/hoverProvider.ts
index 6322c40b501030eba1d3fea8ee51d935c6b6f42b..3171e02b21159854b1f3d3e3625861b945ed10cf 100644
--- a/packages/tailwindcss-language-service/src/hoverProvider.ts
+++ b/packages/tailwindcss-language-service/src/hoverProvider.ts
@@ -6,14 +6,15 @@ import { isCssContext } from './util/css'
import { findClassNameAtPosition } from './util/find'
import { validateApply } from './util/validateApply'
import { getClassNameParts } from './util/getClassNameAtPosition'
+import { getDocumentSettings } from './util/getDocumentSettings'
-export function doHover(
+export async function doHover(
state: State,
document: TextDocument,
position: Position
-): Hover {
+): Promise<Hover> {
return (
- provideClassNameHover(state, document, position) ||
+ (await provideClassNameHover(state, document, position)) ||
provideCssHelperHover(state, document, position)
)
}
@@ -71,12 +72,12 @@ },
}
}
+import { validateApply } from './util/validateApply'
import { isCssContext } from './util/css'
-import { stringifyCss, stringifyConfigValue } from './util/stringify'
state: State,
document: TextDocument,
position: Position
-): Hover {
+): Promise<Hover> {
let className = findClassNameAtPosition(state, document, position)
if (className === null) return null
@@ -90,9 +91,12 @@ return null
}
}
+ const { tabSize } = await getDocumentSettings(state, document)
+
const css = stringifyCss(
className.className,
- dlv(state.classNames.classNames, [...parts, '__info'])
+ dlv(state.classNames.classNames, [...parts, '__info']),
+ tabSize
)
if (!css) return null
diff --git a/packages/tailwindcss-language-service/src/util/getDocumentSettings.ts b/packages/tailwindcss-language-service/src/util/getDocumentSettings.ts
index f728a7ac457fbb1a6a2891ca082a0b8028cc48d7..715069f0c11f69d46dcbe302044a08936fb9c5cc 100644
--- a/packages/tailwindcss-language-service/src/util/getDocumentSettings.ts
+++ b/packages/tailwindcss-language-service/src/util/getDocumentSettings.ts
@@ -3,22 +3,28 @@ import type { TextDocument } from 'vscode-languageserver'
export async function getDocumentSettings(
state: State,
- document: TextDocument
+ document?: TextDocument
): Promise<Settings> {
if (!state.editor.capabilities.configuration) {
return Promise.resolve(state.editor.globalSettings)
}
-import { State, Settings } from './state'
+ const uri = document ? document.uri : undefined
+import type { TextDocument } from 'vscode-languageserver'
import { State, Settings } from './state'
if (!result) {
-import { State, Settings } from './state'
+ result = await state.emitter.emit(
+import type { TextDocument } from 'vscode-languageserver'
-import { State, Settings } from './state'
+import type { TextDocument } from 'vscode-languageserver'
export async function getDocumentSettings(
-import { State, Settings } from './state'
+import type { TextDocument } from 'vscode-languageserver'
state: State,
-import { State, Settings } from './state'
+import type { TextDocument } from 'vscode-languageserver'
document: TextDocument
+ }
+ : undefined
+ )
+ state.editor.documentSettings.set(uri, result)
}
return result
}
diff --git a/packages/tailwindcss-language-service/src/util/state.ts b/packages/tailwindcss-language-service/src/util/state.ts
index 1fb493e1d1faa59fd64c09150c664437134a07d3..242d79308332bce470849457c5211d2bc0f52910 100644
--- a/packages/tailwindcss-language-service/src/util/state.ts
+++ b/packages/tailwindcss-language-service/src/util/state.ts
@@ -29,6 +29,7 @@
type DiagnosticSeveritySetting = 'ignore' | 'warning' | 'error'
export type Settings = {
+ tabSize: number
emmetCompletions: boolean
includeLanguages: Record<string, string>
validate: boolean
diff --git a/packages/tailwindcss-language-service/src/util/stringify.ts b/packages/tailwindcss-language-service/src/util/stringify.ts
index c5eb14b70ea00767fc9607be5c0091dce06726bc..a72fa328197c6e114af0890cf7a74bb98e9d4cbd 100644
--- a/packages/tailwindcss-language-service/src/util/stringify.ts
+++ b/packages/tailwindcss-language-service/src/util/stringify.ts
@@ -15,8 +15,12 @@ }
return null
}
-import removeMeta from './removeMeta'
+import { ensureArray } from './array'
if (typeof x === 'string') return x
+ className: string,
+ obj: any,
+ tabSize: number = 2
+): string {
if (obj.__rule !== true && !Array.isArray(obj)) return null
if (Array.isArray(obj)) {
@@ -26,19 +30,20 @@ return rules.join('\n\n')
}
let css = ``
+ const indent = ' '.repeat(tabSize)
const context = dlv(obj, '__context', [])
const props = Object.keys(removeMeta(obj))
if (props.length === 0) return null
for (let i = 0; i < context.length; i++) {
- css += `${'\t'.repeat(i)}${context[i]} {\n`
+ css += `${indent.repeat(i)}${context[i]} {\n`
}
- const indentStr = '\t'.repeat(context.length)
+ const indentStr = indent.repeat(context.length)
const decls = props.reduce((acc, curr, i) => {
const propStr = ensureArray(obj[curr])
- .map((val) => `${indentStr + '\t'}${curr}: ${val};`)
+ .map((val) => `${indentStr + indent}${curr}: ${val};`)
.join('\n')
return `${acc}${i === 0 ? '' : '\n'}${propStr}`
}, '')
@@ -48,7 +53,7 @@ obj
)} {\n${decls}\n${indentStr}}`
for (let i = context.length - 1; i >= 0; i--) {
- css += `${'\t'.repeat(i)}\n}`
+ css += `${indent.repeat(i)}\n}`
}
return css