1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
diff --git a/packages/tailwindcss-language-service/src/completionProvider.ts b/packages/tailwindcss-language-service/src/completionProvider.ts
index 0ca4912421f22290fee572e99e5184bc34314bb8..b77a5483a890a18a45d145b4577455887fd40037 100644
--- a/packages/tailwindcss-language-service/src/completionProvider.ts
+++ b/packages/tailwindcss-language-service/src/completionProvider.ts
@@ -412,6 +412,36 @@ state.editor.capabilities.itemDefaults
)
}
+// This might be a VS Code bug?
+// The trigger character is not included in the document text
+function ensureTriggerCharacterIsIncluded(
+ text: string,
+ document: TextDocument,
+ position: Position,
+ context?: CompletionContext
+): string {
+ if (!context) {
+ return text
+ }
+ if (
+ context.triggerKind === 2 && // CompletionTriggerKind.TriggerCharacter
+ text.slice(-1) !== context.triggerCharacter
+ ) {
+ let nextChar = document.getText({
+ start: position,
+ end: document.positionAt(document.offsetAt(position) + 1),
+ })
+ // If there's a next char (i.e. we're not at the end of the document)
+ // then it will be included instead of the trigger character, so we replace it.
+ // Otherwise we just append.
+ if (nextChar.length === 0) {
+ return `${text}${context.triggerCharacter}`
+ }
+ return `${text.slice(0, text.length - 1)}${context.triggerCharacter}`
+ }
+ return text
+}
+
async function provideClassAttributeCompletions(
state: State,
document: TextDocument,
@@ -422,6 +452,8 @@ let str = document.getText({
start: document.positionAt(Math.max(0, document.offsetAt(position) - 1000)),
end: position,
})
+
+ str = ensureTriggerCharacterIsIncluded(str, document, position, context)
let matches = matchClassAttributes(
str,
@@ -545,12 +577,15 @@
function provideAtApplyCompletions(
state: State,
document: TextDocument,
- position: Position
+ position: Position,
+ context?: CompletionContext
): CompletionList {
let str = document.getText({
start: { line: Math.max(position.line - 30, 0), character: 0 },
end: position,
})
+
+ str = ensureTriggerCharacterIsIncluded(str, document, position, context)
const match = findLast(/@apply\s+(?<classList>[^;}]*)$/gi, str)
@@ -596,7 +631,7 @@ position: Position,
context?: CompletionContext
): Promise<CompletionList> {
if (isCssContext(state, document, position)) {
- return provideAtApplyCompletions(state, document, position)
+ return provideAtApplyCompletions(state, document, position, context)
}
if (isHtmlContext(state, document, position) || isJsxContext(state, document, position)) {
|