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
Prev Previous commit
more defaults
  • Loading branch information
bradlc committed Jan 27, 2023
commit d9e68c4517b8d9e82a2b42ddf3e42fd23f9fb938
27 changes: 4 additions & 23 deletions packages/tailwindcss-language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ async function createProjectService(

let state: State = {
enabled: false,
completionItemData: {
_projectKey: projectKey,
},
editor: {
connection,
folder,
Expand Down Expand Up @@ -1125,29 +1128,7 @@ 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

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,
...(item.data ? { data: { _projectKey: projectKey, ...item.data } } : {}),
})),
}
return doComplete(state, document, params.position, params.context)
}, null)
},
onCompletionResolve(item: CompletionItem): Promise<CompletionItem> {
Expand Down
Loading