Skip to content

Commit

Permalink
Use itemDefaults to reduce size of completion lists (#706)
Browse files Browse the repository at this point in the history
* Use completion list `itemDefaults`

* more defaults
  • Loading branch information
bradlc committed Jan 27, 2023
1 parent 7235aea commit 637f838
Show file tree
Hide file tree
Showing 5 changed files with 513 additions and 415 deletions.
28 changes: 17 additions & 11 deletions packages/tailwindcss-language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,21 @@ async function createProjectService(
const disposables: Array<Disposable | Promise<Disposable>> = []
let documentSelector = projectConfig.documentSelector

let itemDefaults =
params.capabilities.textDocument?.completion?.completionList?.itemDefaults ?? []

// VS Code _does_ support `itemDefaults.data` since at least 1.67.0 (this extension's min version)
// but it doesn't advertise it in its capabilities. So we manually add it here.
// See also: https://github.com/microsoft/vscode-languageserver-node/issues/1181
if (params.clientInfo?.name === 'Visual Studio Code' && !itemDefaults.includes('data')) {
itemDefaults.push('data')
}

let state: State = {
enabled: false,
completionItemData: {
_projectKey: projectKey,
},
editor: {
connection,
folder,
Expand All @@ -390,6 +403,7 @@ async function createProjectService(
capabilities: {
configuration: true,
diagnosticRelatedInformation: true,
itemDefaults,
},
documents: documentService.documents,
getConfiguration,
Expand Down Expand Up @@ -1114,21 +1128,13 @@ async function createProjectService(
let settings = await state.editor.getConfiguration(document.uri)
if (!settings.tailwindCSS.suggestions) return null
if (await isExcluded(state, document)) return null
let result = await doComplete(state, document, params.position, params.context)
if (!result) return result
return {
isIncomplete: result.isIncomplete,
items: result.items.map((item) => ({
...item,
data: { projectKey, originalData: item.data },
})),
}
return doComplete(state, document, params.position, params.context)
}, null)
},
onCompletionResolve(item: CompletionItem): Promise<CompletionItem> {
return withFallback(() => {
if (!state.enabled) return null
return resolveCompletionItem(state, { ...item, data: item.data?.originalData })
return resolveCompletionItem(state, item)
}, null)
},
async onCodeAction(params: CodeActionParams): Promise<CodeAction[]> {
Expand Down Expand Up @@ -2162,7 +2168,7 @@ class TW {
}

async onCompletionResolve(item: CompletionItem): Promise<CompletionItem> {
return this.projects.get(item.data.projectKey)?.onCompletionResolve(item) ?? null
return this.projects.get(item.data?._projectKey)?.onCompletionResolve(item) ?? null
}

onCodeAction(params: CodeActionParams): Promise<CodeAction[]> {
Expand Down
Loading

0 comments on commit 637f838

Please sign in to comment.