|
6 | 6 | import * as vscode from 'vscode'; |
7 | 7 | import { Node, Stylesheet } from 'EmmetNode'; |
8 | 8 | import { isValidLocationForEmmetAbbreviation } from './abbreviationActions'; |
9 | | -import { getEmmetHelper, getMappingForIncludedLanguages, parsePartialStylesheet, getEmmetConfiguration, getEmmetMode, isStyleSheet, parseDocument, getNode } from './util'; |
10 | | -import { getLanguageService, TextDocument, TokenType } from 'vscode-html-languageservice'; |
| 9 | +import { getEmmetHelper, getMappingForIncludedLanguages, parsePartialStylesheet, getEmmetConfiguration, getEmmetMode, isStyleSheet, parseDocument, getEmbeddedCssNodeIfAny, isStyleAttribute, getNode } from './util'; |
11 | 10 |
|
12 | 11 | export class DefaultCompletionItemProvider implements vscode.CompletionItemProvider { |
13 | 12 |
|
14 | 13 | private lastCompletionType: string | undefined; |
15 | 14 |
|
16 | | - private htmlLS = getLanguageService(); |
17 | | - |
18 | 15 | public provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, _: vscode.CancellationToken, context: vscode.CompletionContext): Thenable<vscode.CompletionList | undefined> | undefined { |
19 | 16 | const completionResult = this.provideCompletionItemsInternal(document, position, context); |
20 | 17 | if (!completionResult) { |
@@ -79,37 +76,20 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi |
79 | 76 |
|
80 | 77 | } |
81 | 78 | if (validateLocation) { |
82 | | - const lsDoc = TextDocument.create(document.uri.toString(), 'html', 0, document.getText()); |
83 | | - const parsedLsDoc = this.htmlLS.parseHTMLDocument(lsDoc); |
84 | | - const positionOffset = document.offsetAt(position); |
85 | | - const node = parsedLsDoc.findNodeAt(positionOffset); |
86 | | - |
87 | | - if (node.tag === 'script') { |
88 | | - return; |
89 | | - } |
90 | | - if (node.tag === 'style') { |
| 79 | + rootNode = parseDocument(document, false); |
| 80 | + currentNode = getNode(rootNode, position, true); |
| 81 | + if (isStyleAttribute(currentNode, position)) { |
91 | 82 | syntax = 'css'; |
92 | 83 | validateLocation = false; |
93 | 84 | } else { |
94 | | - if (node.attributes && node.attributes['style']) { |
95 | | - const scanner = this.htmlLS.createScanner(document.getText(), node.start); |
96 | | - let tokenType = scanner.scan(); |
97 | | - let prevAttr = undefined; |
98 | | - while (tokenType !== TokenType.EOS && (scanner.getTokenEnd() <= positionOffset)) { |
99 | | - tokenType = scanner.scan(); |
100 | | - if (tokenType === TokenType.AttributeName) { |
101 | | - prevAttr = scanner.getTokenText(); |
102 | | - } |
103 | | - } |
104 | | - if (prevAttr === 'style') { |
105 | | - syntax = 'css'; |
106 | | - validateLocation = false; |
107 | | - } |
| 85 | + const embeddedCssNode = getEmbeddedCssNodeIfAny(document, currentNode, position); |
| 86 | + if (embeddedCssNode) { |
| 87 | + currentNode = getNode(embeddedCssNode, position, true); |
| 88 | + syntax = 'css'; |
108 | 89 | } |
109 | 90 | } |
110 | 91 | } |
111 | 92 |
|
112 | | - |
113 | 93 | } |
114 | 94 |
|
115 | 95 | const extractAbbreviationResults = helper.extractAbbreviation(document, position, !isStyleSheet(syntax)); |
|
0 commit comments