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(+), 46 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
@@ -155,7 +155,11 @@ let emitter = createEmitter(client)
registerConfigErrorHandler(emitter)
registerColorDecorator(client, context, emitter)
onMessage(client, 'getConfiguration', async (scope) => {
- return Workspace.getConfiguration('tailwindCSS', scope)
+ return {
+ 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)
})
@@ -206,14 +203,14 @@ }
)
connection.onCompletionResolve(
- (item: CompletionItem): CompletionItem => {
+ (item: CompletionItem): Promise<CompletionItem> => {
if (!state.enabled) return null
return resolveCompletionItem(state, item)
}
)
connection.onHover(
- (params: TextDocumentPositionParams): Hover => {
+ (params: TextDocumentPositionParams): Promise<Hover> => {
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,10 +720,10 @@
return provideEmmetCompletions(state, document, position)
}
-export function resolveCompletionItem(
+export async function resolveCompletionItem(
state: State,
item: CompletionItem
-): CompletionItem {
+): Promise<CompletionItem> {
if (['helper', 'directive', 'variant', '@tailwind'].includes(item.data)) {
return item
}
@@ -747,7 +747,8 @@ ].join(', ')
} else {
item.detail = getCssDetail(state, className)
if (!item.documentation) {
- const css = stringifyCss(item.data.join(':'), className)
+ const { tabSize } = await getDocumentSettings(state)
+ const css = stringifyCss(item.data.join(':'), className, tabSize)
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,11 +72,11 @@ },
}
}
-function provideClassNameHover(
+async function provideClassNameHover(
state: State,
document: TextDocument,
position: Position
-): Hover {
+): Promise<Hover> {
let className = findClassNameAtPosition(state, document, position)
if (className === null) return null
@@ -89,9 +90,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,17 +3,23 @@ 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)
}
- let result = state.editor.documentSettings.get(document.uri)
+ const uri = document ? document.uri : undefined
+ let result = state.editor.documentSettings.get(uri)
if (!result) {
- result = await state.emitter.emit('getConfiguration', {
- languageId: document.languageId,
- })
- state.editor.documentSettings.set(document.uri, result)
+ result = await state.emitter.emit(
+ 'getConfiguration',
+ document
+ ? {
+ languageId: document.languageId,
+ }
+ : 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,7 +15,11 @@ }
return null
}
-export function stringifyCss(className: string, obj: any): string {
+export function stringifyCss(
+ className: string,
+ obj: any,
+ tabSize: number = 2
+): string {
if (obj.__rule !== true && !Array.isArray(obj)) return null
if (Array.isArray(obj)) {
@@ -25,19 +29,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}`
}, '')
@@ -47,7 +52,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