Skip to content

Avoid getting settings twice when doing completions #782

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

Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions packages/tailwindcss-language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import { getColor } from 'tailwindcss-language-service/src/util/color'
import * as culori from 'culori'
import namedColors from 'color-name'
import tailwindPlugins from './lib/plugins'
import isExcluded from './util/isExcluded'
import isExcluded, { isExcludedOnComplete } from './util/isExcluded'
import { getFileFsPath, normalizeFileNameToFsPath } from './util/uri'
import { equal } from 'tailwindcss-language-service/src/util/array'
import preflight from 'tailwindcss/lib/css/preflight.css'
Expand Down Expand Up @@ -1169,7 +1169,7 @@ async function createProjectService(
if (!document) return null
let settings = await state.editor.getConfiguration(document.uri)
if (!settings.tailwindCSS.suggestions) return null
if (await isExcluded(state, document)) return null
if (await isExcludedOnComplete(state, document, settings)) return null
return doComplete(state, document, params.position, params.context)
}, null)
},
Expand Down
17 changes: 16 additions & 1 deletion packages/tailwindcss-language-server/src/util/isExcluded.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import minimatch from 'minimatch'
import * as path from 'path'
import { State } from 'tailwindcss-language-service/src/util/state'
import { Settings, State } from 'tailwindcss-language-service/src/util/state'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { getFileFsPath } from './uri'

Expand All @@ -19,3 +19,18 @@ export default async function isExcluded(

return false
}

export async function isExcludedOnComplete(
state: State,
document: TextDocument,
settings: Settings,
file: string = getFileFsPath(document.uri)
): Promise<boolean> {
for (let pattern of settings.tailwindCSS.files.exclude) {
if (minimatch(file, path.join(state.editor.folder, pattern))) {
return true
}
}

return false
}