Skip to content

Make class search range larger #1192

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 5 commits into from
Feb 12, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ import { IS_SCRIPT_SOURCE, IS_TEMPLATE_SOURCE } from './metadata/extensions'
import * as postcss from 'postcss'
import { findFileDirective } from './completions/file-paths'
import type { ThemeEntry } from './util/v4'
import { posix } from 'node:path/win32'
import { segment } from './util/segment'
import { resolveKnownThemeKeys, resolveKnownThemeNamespaces } from './util/v4/theme-keys'
import { SEARCH_RANGE } from './util/constants'

let isUtil = (className) =>
Array.isArray(className.__info)
Expand Down Expand Up @@ -729,7 +729,7 @@ async function provideClassAttributeCompletions(
context?: CompletionContext,
): Promise<CompletionList> {
let str = document.getText({
start: document.positionAt(Math.max(0, document.offsetAt(position) - 2000)),
start: document.positionAt(Math.max(0, document.offsetAt(position) - SEARCH_RANGE)),
end: position,
})

Expand Down Expand Up @@ -796,7 +796,7 @@ async function provideCustomClassNameCompletions(

let text = document.getText({
start: document.positionAt(0),
end: document.positionAt(cursor + 2000),
end: document.positionAt(cursor + SEARCH_RANGE),
})

// Get completions from the first matching regex or regex pair
Expand Down
4 changes: 4 additions & 0 deletions packages/tailwindcss-language-service/src/util/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* The maximum bounds around the cursor when searching for class names
*/
export const SEARCH_RANGE = 15_000
5 changes: 3 additions & 2 deletions packages/tailwindcss-language-service/src/util/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { resolveRange } from './resolveRange'
import { getTextWithoutComments } from './doc'
import { isSemicolonlessCssLanguage } from './languages'
import { customClassesIn } from './classes'
import { SEARCH_RANGE } from './constants'

export function findAll(re: RegExp, str: string): RegExpMatchArray[] {
let match: RegExpMatchArray
Expand Down Expand Up @@ -437,8 +438,8 @@ export async function findClassNameAtPosition(
let classNames: DocumentClassName[] = []
const positionOffset = doc.offsetAt(position)
const searchRange: Range = {
start: doc.positionAt(Math.max(0, positionOffset - 2000)),
end: doc.positionAt(positionOffset + 2000),
start: doc.positionAt(0),
end: doc.positionAt(positionOffset + SEARCH_RANGE),
}

if (isVueDoc(doc)) {
Expand Down
1 change: 1 addition & 0 deletions packages/vscode-tailwindcss/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Fix suggestion of utilities with slashes in them in v4 ([#1182](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1182))
- Assume 16px font size for `1rem` in media queries ([#1190](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1190))
- Show warning when loading a config in v3 fails ([#1191](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1191))
- Better handle really long class lists in attributes and custom regexes ([#1192](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1192))

## 0.14.3

Expand Down