Skip to content

Use itemDefaults to reduce size of completion lists #706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use completion list itemDefaults
  • Loading branch information
bradlc committed Jan 23, 2023
commit 643efb5c388b13533ca4628832b90abb681612f5
31 changes: 28 additions & 3 deletions packages/tailwindcss-language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,16 @@ 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,
editor: {
Expand All @@ -390,6 +400,7 @@ async function createProjectService(
capabilities: {
configuration: true,
diagnosticRelatedInformation: true,
itemDefaults,
},
documents: documentService.documents,
getConfiguration,
Expand Down Expand Up @@ -1116,19 +1127,33 @@ async function createProjectService(
if (await isExcluded(state, document)) return null
let result = await doComplete(state, document, params.position, params.context)
if (!result) return result

let supportsDefaults = state.editor.capabilities.itemDefaults.length > 0
let supportsDefaultData = state.editor.capabilities.itemDefaults.includes('data')

return {
isIncomplete: result.isIncomplete,
...(supportsDefaults
? {
itemDefaults: {
...(result.itemDefaults ?? {}),
...(supportsDefaultData
? { data: { _projectKey: projectKey, ...(result.itemDefaults?.data ?? {}) } }
: {}),
},
}
: {}),
items: result.items.map((item) => ({
...item,
data: { projectKey, originalData: item.data },
...(item.data ? { data: { _projectKey: projectKey, ...item.data } } : {}),
})),
}
}, 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 +2187,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