diff --git a/package-lock.json b/package-lock.json index f844afb78a3c31adf7b940746d88f9e90ad99f41..d3461d15178fbd81895623d655bde63ebf413264 100755 --- a/package-lock.json +++ b/package-lock.json @@ -1034,13 +1034,6 @@ "integrity": "sha512-dOrgprHnkDaj1pmrwdcMAf0QRNQzqTB5rxJph+iIQshSmIvtgRqJ0nim8u1vvXU8iOXZrH96+M46JDFTPLingA==", "dev": true }, "lockfileVersion": 1, - "version": "7.9.6", - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/@types/moo/-/moo-0.5.3.tgz", - "integrity": "sha512-PJJ/jvb5Gor8DWvXN3e75njfQyYNRz0PaFSZ3br9GfHM9N2FxvuJ/E/ytcQePJOLzHlvgFSsIJIvfUMUxWTbnA==", - "dev": true - }, - "lockfileVersion": 1, "@babel/generator": "^7.9.6", "version": "13.13.4", "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.4.tgz", @@ -4949,12 +4942,6 @@ "mkdirp": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.3.tgz", "integrity": "sha512-6uCP4Qc0sWsgMLy1EOqqS/3rjDHOEnsStVr/4vtAIK2Y5i2kA7lFFejYrpIyiN9w0pYf4ckeCYT9f1r1P9KX5g==", - "dev": true - }, - "moo": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/moo/-/moo-0.5.1.tgz", - "integrity": "sha512-I1mnb5xn4fO80BH9BLcF0yLypy2UKl+Cb01Fu0hJRkJjlCRtxZMWkTdAtDd5ZqCOxtCkhmRwyI57vWT+1iZ67w==", "dev": true }, "ms": { diff --git a/package.json b/package.json index 0b515cadd282395481a1489f142d1b951f894696..69d62d97f70770c055be6a9d69bc98fb4d3f295a 100755 --- a/package.json +++ b/package.json @@ -44,8 +44,7 @@ "source.css.scss", "source.css.less", "source.css.postcss", "source.vue", - "source.svelte", - "text.html" + "source.svelte" ] } ], @@ -77,8 +76,6 @@ "devDependencies": { "@ctrl/tinycolor": "^3.1.0", "@types/mocha": "^5.2.0", "license": "MIT", - "name": "vscode-tailwindcss", - "license": "MIT", "displayName": "Tailwind CSS IntelliSense", "@types/vscode": "^1.32.0", "@zeit/ncc": "^0.22.0", @@ -97,7 +94,6 @@ "jest": "^25.5.4", "line-column": "^1.0.2", "mitt": "^1.2.0", "mkdirp": "^1.0.3", - "moo": "^0.5.1", "pkg-up": "^3.1.0", "postcss": "^7.0.27", "postcss-selector-parser": "^6.0.2", diff --git a/src/lib/languages.ts b/src/lib/languages.ts index 777f5885f033174f1163d970cece03505d7dd0e8..b9238edde46be72d6b7a5db044b063e57666efff 100644 --- a/src/lib/languages.ts +++ b/src/lib/languages.ts @@ -32,13 +32,10 @@ 'sass', 'scss', 'stylus', 'aspnetcorerazor', - 'blade', - 'aspnetcorerazor', 'django-html', 'javascript', 'javascriptreact', 'reason', - 'typescript', 'typescriptreact', // mixed 'vue', diff --git a/src/lsp/providers/completionProvider.ts b/src/lsp/providers/completionProvider.ts index eae7546bffc68d70c05ef1ebbdd0353fac33a42d..8f2c43d8325bc847a7b05a87dc180025a647f2a9 100644 --- a/src/lsp/providers/completionProvider.ts +++ b/src/lsp/providers/completionProvider.ts @@ -12,7 +12,7 @@ import removeMeta from '../util/removeMeta' import { getColor, getColorFromValue } from '../util/color' import { isHtmlContext } from '../util/html' import { isCssContext } from '../util/css' -import { findLast } from '../util/find' +import { findLast, findJsxStrings, arrFindLast } from '../util/find' import { stringifyConfigValue, stringifyCss } from '../util/stringify' import { stringifyScreen, Screen } from '../util/screens' import isObject from '../../util/isObject' @@ -24,10 +24,6 @@ import { naturalExpand } from '../util/naturalExpand' import semver from 'semver' import { docsUrl } from '../util/docsUrl' import { ensureArray } from '../../util/array' -import { - getClassAttributeLexer, - getComputedClassAttributeLexer, -} from '../util/lexers' function completionsFromClassList( state: State, @@ -126,45 +122,38 @@ start: { line: Math.max(position.line - 10, 0), character: 0 }, end: position, }) -import removeMeta from '../util/removeMeta' CompletionItemKind, + if (match === null) { return null } - const lexer = - match[0][0] === ':' -import { State } from '../util/state' + let isSubset: boolean = false import { State } from '../util/state' -} from 'vscode-languageserver' -import { getColor, getColorFromValue } from '../util/color' + CompletionItem, -import { State } from '../util/state' + let isSubset: boolean = false import { -import { State } from '../util/state' + let isSubset: boolean = false CompletionItem, - try { -import { getColor, getColorFromValue } from '../util/color' + CompletionItemKind, CompletionItem, -import { getColor, getColorFromValue } from '../util/color' CompletionItemKind, -import { getColor, getColorFromValue } from '../util/color' + let isSubset: boolean = false CompletionParams, -import { getColor, getColorFromValue } from '../util/color' + let isSubset: boolean = false Range, - for (let i = tokens.length - 1; i >= 0; i--) { -import { getColor, getColorFromValue } from '../util/color' + filter?: (item: CompletionItem) => boolean CompletionList, - classList = tokens[i].value + classList + if (lastOpenString) { - CompletionList, + CompletionItemKind, CompletionItem, + CompletionList, -import { State } from '../util/state' + CompletionItemKind, CompletionItem, - CompletionList, } from 'vscode-languageserver' +import { State } from '../util/state' Range, - Range, - CompletionItem, return completionsFromClassList(state, classList, { start: { line: position.line, @@ -173,11 +163,22 @@ end: position, }) } import { State } from '../util/state' +import { stringifyConfigValue, stringifyCss } from '../util/stringify' + } CompletionItem, + if (rest.indexOf(match.groups.initial) !== -1) { + return null CompletionParams, + let replacementRange = { import { State } from '../util/state' + start: { ): CompletionList { +} from 'vscode-languageserver' + character: position.character - rest.length, + }, + end: position, + }) } function provideAtApplyCompletions( diff --git a/src/lsp/providers/diagnosticsProvider.ts b/src/lsp/providers/diagnosticsProvider.ts index 152f3b76a3c0a9d10f37c63f42bdcdc6e5d8a4e1..66e0f4cdc90d8f09bd9c9c619e8177875cae5ba9 100644 --- a/src/lsp/providers/diagnosticsProvider.ts +++ b/src/lsp/providers/diagnosticsProvider.ts @@ -10,7 +10,7 @@ import { getClassNameParts } from '../util/getClassNameAtPosition' const dlv = require('dlv') function provideCssDiagnostics(state: State, document: TextDocument): void { - const classNames = findClassNamesInRange(document, undefined, 'css') + const classNames = findClassNamesInRange(document) let diagnostics: Diagnostic[] = classNames .map(({ className, range }) => { diff --git a/src/lsp/providers/hoverProvider.ts b/src/lsp/providers/hoverProvider.ts index a9010a3142cb4e9700f63e3bd06426a144b9afa0..7e27d9ac9833ec166a6332607b38562ec0b03f80 100644 --- a/src/lsp/providers/hoverProvider.ts +++ b/src/lsp/providers/hoverProvider.ts @@ -1,10 +1,17 @@ -import { State } from '../util/state' +import { State, DocumentClassName } from '../util/state' import { Hover, TextDocumentPositionParams } from 'vscode-languageserver' -import { getClassNameParts } from '../util/getClassNameAtPosition' +import { + getClassNameAtPosition, + getClassNameParts, +} from '../util/getClassNameAtPosition' import { stringifyCss, stringifyConfigValue } from '../util/stringify' const dlv = require('dlv') import { isCssContext } from '../util/css' +export function provideHover( +import { isCssContext } from '../util/css' import { findClassNameAtPosition } from '../util/find' +import { isWithinRange } from '../util/isWithinRange' +import { findClassNamesInRange } from '../util/find' export function provideHover( state: State, @@ -69,33 +76,80 @@ }, } } -function provideClassNameHover( +function provideClassAttributeHover( state: State, { textDocument, position }: TextDocumentPositionParams ): Hover { let doc = state.editor.documents.get(textDocument.uri) + if ( + !isHtmlContext(state, doc, position) && + !isJsContext(state, doc, position) +import { State } from '../util/state' const dlv = require('dlv') import { getClassNameParts } from '../util/getClassNameAtPosition' +import { State } from '../util/state' + + let hovered = getClassNameAtPosition(doc, position) - if (className === null) return null + if (!hovered) return null + + return classNameToHover(state, hovered) +} + + state: State, + { className, range }: DocumentClassName - const parts = getClassNameParts(state, className.className) +): Hover { + const parts = getClassNameParts(state, className) if (!parts) return null return { contents: { language: 'css', + value: stringifyCss(className, dlv(state.classNames.classNames, parts)), const dlv = require('dlv') -export function provideHover( +import { State } from '../util/state' + range, + } +import { State } from '../util/state' import { isCssContext } from '../util/css' + +function provideAtApplyHover( +import { State } from '../util/state' -import { isCssContext } from '../util/css' import { State } from '../util/state' + +): Hover { + let doc = state.editor.documents.get(textDocument.uri) + + if (!isCssContext(state, doc, position)) return null + + import { isCssContext } from '../util/css' + start: { line: Math.max(position.line - 10, 0), character: 0 }, + end: { line: position.line + 10, character: 0 }, import { Hover, TextDocumentPositionParams } from 'vscode-languageserver' +import { stringifyCss, stringifyConfigValue } from '../util/stringify' + + const className = classNames.find(({ range }) => + isWithinRange(position, range) +import { State } from '../util/state' const dlv = require('dlv') + +export function provideHover( import { State } from '../util/state' + + return classNameToHover(state, className) +import { State } from '../util/state' import { isCssContext } from '../util/css' + +function provideClassNameHover( + state: State, + params: TextDocumentPositionParams +): Hover { +import { State } from '../util/state' import { getClassNameParts } from '../util/getClassNameAtPosition' +export function provideHover( import { getClassNameParts } from '../util/getClassNameAtPosition' -import { Hover, TextDocumentPositionParams } from 'vscode-languageserver' + provideAtApplyHover(state, params) + ) } diff --git a/src/lsp/util/css.ts b/src/lsp/util/css.ts index e6dbd097d4b97c42c4f7f650fc1e1186d33c0047..d1acbea2b4e6e166e57d7d604ac2e615d1e94a0b 100644 --- a/src/lsp/util/css.ts +++ b/src/lsp/util/css.ts @@ -1,5 +1,5 @@ import { TextDocument, Position } from 'vscode-languageserver' -import { isInsideTag, isVueDoc, isSvelteDoc, isHtmlDoc } from './html' +import { isInsideTag, isVueDoc, isSvelteDoc } from './html' import { State } from './state' export const CSS_LANGUAGES = [ @@ -9,7 +9,6 @@ 'postcss', 'sass', 'scss', 'stylus', - 'sugarss', ] export function isCssDoc(state: State, doc: TextDocument): boolean { @@ -29,7 +28,7 @@ if (isCssDoc(state, doc)) { return true } - if (isHtmlDoc(state, doc) || isVueDoc(doc) || isSvelteDoc(doc)) { + if (isVueDoc(doc) || isSvelteDoc(doc)) { let str = doc.getText({ start: { line: 0, character: 0 }, end: position, diff --git a/src/lsp/util/find.ts b/src/lsp/util/find.ts index 800d0a3ce5dd1d133e5dfb1e246faac7abf1ca1c..17b6a127654ae8b748941e828167512078286361 100644 --- a/src/lsp/util/find.ts +++ b/src/lsp/util/find.ts @@ -1,11 +1,8 @@ import { TextDocument, Range, Position } from 'vscode-languageserver' -import { DocumentClassName, DocumentClassList, State } from './state' -import lineColumn from 'line-column' -import { isCssContext } from './css' -import { isHtmlContext } from './html' -import { isWithinRange } from './isWithinRange' +import { TextDocument, Range, Position } from 'vscode-languageserver' import { isJsContext } from './js' +import { isCssContext } from './css' -import { getClassAttributeLexer } from './lexers' +import lineColumn from 'line-column' export function findAll(re: RegExp, str: string): RegExpMatchArray[] { let match: RegExpMatchArray @@ -24,312 +21,191 @@ } return matches[matches.length - 1] } -export function findClassNamesInRange( - doc: TextDocument, - range?: Range, - mode?: 'html' | 'css' -): DocumentClassName[] { - const classLists = findClassListsInRange(doc, range, mode) - return [].concat.apply( - [], -import lineColumn from 'line-column' import { TextDocument, Range, Position } from 'vscode-languageserver' - const parts = classList.split(/(\s+)/) - const names: DocumentClassName[] = [] - let index = 0 - for (let i = 0; i < parts.length; i++) { - if (i % 2 === 0) { -import lineColumn from 'line-column' import { isJsContext } from './js' - const end = indexToPosition(classList, index + parts[i].length) - names.push({ - className: parts[i], - range: { - start: { - line: range.start.line + start.line, - character: -import { isCssContext } from './css' import { isHtmlContext } from './html' -import { isCssContext } from './css' +} import { isWithinRange } from './isWithinRange' -import { isCssContext } from './css' +import { TextDocument, Range, Position } from 'vscode-languageserver' import { isJsContext } from './js' - end: { - line: range.start.line + end.line, - character: - (end.line === 0 ? range.start.character : 0) + end.character, -import { isCssContext } from './css' import { isJsContext } from './js' -import { isHtmlContext } from './html' import { TextDocument, Range, Position } from 'vscode-languageserver' - }) - } - index += parts[i].length - } - return names -import { isHtmlContext } from './html' import { isJsContext } from './js' -import { isHtmlContext } from './html' import { getClassAttributeLexer } from './lexers' } -export function findClassListsInCssRange( +import { getClassAttributeLexer } from './lexers' import { DocumentClassName, DocumentClassList, State } from './state' -import { isCssContext } from './css' - range?: Range -import { isWithinRange } from './isWithinRange' import { TextDocument, Range, Position } from 'vscode-languageserver' - const text = doc.getText(range) - const matches = findAll(/(@apply\s+)(?[^;}]+)[;}]/g, text) - const globalStart: Position = range ? range.start : { line: 0, character: 0 } - -import { isWithinRange } from './isWithinRange' import { isHtmlContext } from './html' - const start = indexToPosition(text, match.index + match[1].length) - const end = indexToPosition( -import { isWithinRange } from './isWithinRange' +import { TextDocument, Range, Position } from 'vscode-languageserver' import { getClassAttributeLexer } from './lexers' - match.index + match[1].length + match.groups.classList.length -import { isJsContext } from './js' -import { isJsContext } from './js' import { TextDocument, Range, Position } from 'vscode-languageserver' import { isJsContext } from './js' -import { DocumentClassName, DocumentClassList, State } from './state' - range: { - start: { - line: globalStart.line + start.line, - character: globalStart.character + start.character, - }, - end: { -import { isJsContext } from './js' +import { TextDocument, Range, Position } from 'vscode-languageserver' import { getClassAttributeLexer } from './lexers' - }, +import { TextDocument, Range, Position } from 'vscode-languageserver' -import { getClassAttributeLexer } from './lexers' import { TextDocument, Range, Position } from 'vscode-languageserver' } +import { TextDocument, Range, Position } from 'vscode-languageserver' }) import { TextDocument, Range, Position } from 'vscode-languageserver' -import { isJsContext } from './js' - export function findClassListsInHtmlRange( - doc: TextDocument, +} +import { TextDocument, Range, Position } from 'vscode-languageserver' range: Range -import { isWithinRange } from './isWithinRange' import { TextDocument, Range, Position } from 'vscode-languageserver' - const text = doc.getText(range) const matches = findAll(/[\s:]class(?:Name)?=['"`{]/g, text) +import { TextDocument, Range, Position } from 'vscode-languageserver' const result: DocumentClassList[] = [] - +import { TextDocument, Range, Position } from 'vscode-languageserver' matches.forEach((match) => { -import { getClassAttributeLexer } from './lexers' +} +export function findLast(re: RegExp, str: string): RegExpMatchArray { +import { TextDocument, Range, Position } from 'vscode-languageserver' let lexer = getClassAttributeLexer() +import { TextDocument, Range, Position } from 'vscode-languageserver' lexer.reset(subtext) - +import { TextDocument, Range, Position } from 'vscode-languageserver' let classLists: { value: string; offset: number }[] = [] +import { TextDocument, Range, Position } from 'vscode-languageserver' let token: moo.Token +import { TextDocument, Range, Position } from 'vscode-languageserver' let currentClassList: { value: string; offset: number } - +import { TextDocument, Range, Position } from 'vscode-languageserver' try { +import { TextDocument, Range, Position } from 'vscode-languageserver' for (let token of lexer) { +import { TextDocument, Range, Position } from 'vscode-languageserver' if (token.type === 'classlist') { +import { TextDocument, Range, Position } from 'vscode-languageserver' if (currentClassList) { +import { TextDocument, Range, Position } from 'vscode-languageserver' currentClassList.value += token.value -import { TextDocument, Range, Position } from 'vscode-languageserver' +import { DocumentClassName, DocumentClassList, State } from './state' -import { TextDocument, Range, Position } from 'vscode-languageserver' +import { DocumentClassName, DocumentClassList, State } from './state' import { TextDocument, Range, Position } from 'vscode-languageserver' -import { TextDocument, Range, Position } from 'vscode-languageserver' +import { DocumentClassName, DocumentClassList, State } from './state' import { DocumentClassName, DocumentClassList, State } from './state' -import { TextDocument, Range, Position } from 'vscode-languageserver' +import { DocumentClassName, DocumentClassList, State } from './state' import lineColumn from 'line-column' -import { TextDocument, Range, Position } from 'vscode-languageserver' +import { DocumentClassName, DocumentClassList, State } from './state' import { isCssContext } from './css' -import { TextDocument, Range, Position } from 'vscode-languageserver' +import { DocumentClassName, DocumentClassList, State } from './state' import { isHtmlContext } from './html' -import { TextDocument, Range, Position } from 'vscode-languageserver' +import { DocumentClassName, DocumentClassList, State } from './state' import { isWithinRange } from './isWithinRange' - if (currentClassList) { -import { TextDocument, Range, Position } from 'vscode-languageserver' +import { DocumentClassName, DocumentClassList, State } from './state' import { isJsContext } from './js' -import { TextDocument, Range, Position } from 'vscode-languageserver' +import { DocumentClassName, DocumentClassList, State } from './state' import { getClassAttributeLexer } from './lexers' - offset: currentClassList.offset, - }) - } - currentClassList = undefined - } } - let match: RegExpMatchArray +import { getClassAttributeLexer } from './lexers' import { DocumentClassName, DocumentClassList, State } from './state' + if (matches.length === 0) { - if (currentClassList) { - classLists.push({ -import { TextDocument, Range, Position } from 'vscode-languageserver' +import { DocumentClassName, DocumentClassList, State } from './state' import { TextDocument, Range, Position } from 'vscode-languageserver' -import { isHtmlContext } from './html' +import { DocumentClassName, DocumentClassList, State } from './state' let match: RegExpMatchArray -import { isWithinRange } from './isWithinRange' - }) } - import { TextDocument, Range, Position } from 'vscode-languageserver' -export function findLast(re: RegExp, str: string): RegExpMatchArray { - ...classLists +import { isHtmlContext } from './html' -import { TextDocument, Range, Position } from 'vscode-languageserver' import { DocumentClassName, DocumentClassList, State } from './state' let matches: RegExpMatchArray[] = [] -import { TextDocument, Range, Position } from 'vscode-languageserver' import { TextDocument, Range, Position } from 'vscode-languageserver' - return matches[matches.length - 1] - } +import { isJsContext } from './js' -import { TextDocument, Range, Position } from 'vscode-languageserver' export function findClassNamesInRange( -import { TextDocument, Range, Position } from 'vscode-languageserver' doc: TextDocument, - const after = value.match(/\s*$/) - let matches: RegExpMatchArray[] = [] import { isWithinRange } from './isWithinRange' - -import { TextDocument, Range, Position } from 'vscode-languageserver' ): DocumentClassName[] { -import { TextDocument, Range, Position } from 'vscode-languageserver' import { DocumentClassName, DocumentClassList, State } from './state' -import { getClassAttributeLexer } from './lexers' import { TextDocument, Range, Position } from 'vscode-languageserver' +import lineColumn from 'line-column' return [].concat.apply( -import { TextDocument, Range, Position } from 'vscode-languageserver' [], -import { TextDocument, Range, Position } from 'vscode-languageserver' classLists.map(({ classList, range }) => { - text, -import { TextDocument, Range, Position } from 'vscode-languageserver' const parts = classList.split(/(\s+)/) -import { TextDocument, Range, Position } from 'vscode-languageserver' const names: DocumentClassName[] = [] -import { TextDocument, Range, Position } from 'vscode-languageserver' let index = 0 -import { TextDocument, Range, Position } from 'vscode-languageserver' for (let i = 0; i < parts.length; i++) { -import { TextDocument, Range, Position } from 'vscode-languageserver' if (i % 2 === 0) { -import { TextDocument, Range, Position } from 'vscode-languageserver' const start = indexToPosition(classList, index) - ) - -import { TextDocument, Range, Position } from 'vscode-languageserver' const end = indexToPosition(classList, index + parts[i].length) -import { TextDocument, Range, Position } from 'vscode-languageserver' names.push({ import { isCssContext } from './css' -import { TextDocument, Range, Position } from 'vscode-languageserver' - start: { - line: range.start.line + start.line, - matches.push({ ...match }) import { isCssContext } from './css' -import { isJsContext } from './js' - end: { - line: range.start.line + end.line, - matches.push({ ...match }) import { TextDocument, Range, Position } from 'vscode-languageserver' import { isCssContext } from './css' -import { isJsContext } from './js' - }, - } - matches.push({ ...match }) import { DocumentClassName, DocumentClassList, State } from './state' -import { TextDocument, Range, Position } from 'vscode-languageserver' line: range.start.line + start.line, - ) - }) - -import { TextDocument, Range, Position } from 'vscode-languageserver' character: -} - -import { TextDocument, Range, Position } from 'vscode-languageserver' (end.line === 0 ? range.start.character : 0) + - doc: TextDocument, -import { TextDocument, Range, Position } from 'vscode-languageserver' start.character, -import { TextDocument, Range, Position } from 'vscode-languageserver' }, -): DocumentClassList[] { -import { TextDocument, Range, Position } from 'vscode-languageserver' end: { -import { TextDocument, Range, Position } from 'vscode-languageserver' line: range.start.line + end.line, - } + character: -import { TextDocument, Range, Position } from 'vscode-languageserver' (end.line === 0 ? range.start.character : 0) + end.character, -import { TextDocument, Range, Position } from 'vscode-languageserver' +import { isCssContext } from './css' import { isJsContext } from './js' - -import { TextDocument, Range, Position } from 'vscode-languageserver' }, -import { TextDocument, Range, Position } from 'vscode-languageserver' }) -import { TextDocument, Range, Position } from 'vscode-languageserver' } -} - -import { TextDocument, Range, Position } from 'vscode-languageserver' index += parts[i].length -import { TextDocument, Range, Position } from 'vscode-languageserver' } - doc: TextDocument, -import { TextDocument, Range, Position } from 'vscode-languageserver' return names -import { TextDocument, Range, Position } from 'vscode-languageserver' }) -import { TextDocument, Range, Position } from 'vscode-languageserver' ) import { TextDocument, Range, Position } from 'vscode-languageserver' -import { isHtmlContext } from './html' +import { isJsContext } from './js' import { TextDocument, Range, Position } from 'vscode-languageserver' + (end.line === 0 ? range.start.character : 0) + + doc: TextDocument, range?: Range -import { TextDocument, Range, Position } from 'vscode-languageserver' ): DocumentClassList[] { - } - -import { TextDocument, Range, Position } from 'vscode-languageserver' const text = doc.getText(range) -import { TextDocument, Range, Position } from 'vscode-languageserver' const matches = findAll(/(@apply\s+)(?[^;}]+)[;}]/g, text) -import { TextDocument, Range, Position } from 'vscode-languageserver' const globalStart: Position = range ? range.start : { line: 0, character: 0 } -import { TextDocument, Range, Position } from 'vscode-languageserver' + return matches.map((match) => { -import { TextDocument, Range, Position } from 'vscode-languageserver' const start = indexToPosition(text, match.index + match[1].length) -import { TextDocument, Range, Position } from 'vscode-languageserver' const end = indexToPosition( -import { TextDocument, Range, Position } from 'vscode-languageserver' text, - } +import { isWithinRange } from './isWithinRange' + ) +import { isJsContext } from './js' import { TextDocument, Range, Position } from 'vscode-languageserver' - match.index + match[1].length + match.groups.classList.length +import { isJsContext } from './js' import { DocumentClassName, DocumentClassList, State } from './state' -import { TextDocument, Range, Position } from 'vscode-languageserver' + range: { + start: { -import { TextDocument, Range, Position } from 'vscode-languageserver' +import { isJsContext } from './js' import { isHtmlContext } from './html' - + character: globalStart.character + start.character, -import { TextDocument, Range, Position } from 'vscode-languageserver' + }, + end: { import { isJsContext } from './js' + +import { getClassAttributeLexer } from './lexers' -import { TextDocument, Range, Position } from 'vscode-languageserver' import { isJsContext } from './js' +import { isJsContext } from './js' +import { getClassAttributeLexer } from './lexers' import { TextDocument, Range, Position } from 'vscode-languageserver' -import { isHtmlContext } from './html' import { getClassAttributeLexer } from './lexers' +import { DocumentClassName, DocumentClassList, State } from './state' - + }) } -import { DocumentClassName, DocumentClassList, State } from './state' import { TextDocument, Range, Position } from 'vscode-languageserver' -import { isJsContext } from './js' + }, + const { line, col } = lineColumn(str + '\n', index) + } import lineColumn from 'line-column' } diff --git a/src/lsp/util/js.ts b/src/lsp/util/js.ts index 495ec5d828cd123e241f579d31711b541ded73a5..8a62a5ff69c8ff4869e8541c6d0eac40a9b1744e 100644 --- a/src/lsp/util/js.ts +++ b/src/lsp/util/js.ts @@ -6,7 +6,6 @@ export const JS_LANGUAGES = [ 'javascript', 'javascriptreact', 'reason', - 'typescript', 'typescriptreact', ] diff --git a/src/lsp/util/lazy.ts b/src/lsp/util/lazy.ts deleted file mode 100644 index 858dac58c1fcc51d0bddc53027a47816db0e942e..0000000000000000000000000000000000000000 --- a/src/lsp/util/lazy.ts +++ /dev/null @@ -1,19 +0,0 @@ -// https://www.codementor.io/@agustinchiappeberrini/lazy-evaluation-and-javascript-a5m7g8gs3 - -export interface Lazy { - (): T - isLazy: boolean -} - -export const lazy = (getter: () => T): Lazy => { - let evaluated: boolean = false - let _res: T = null - const res = >function (): T { - if (evaluated) return _res - _res = getter.apply(this, arguments) - evaluated = true - return _res - } - res.isLazy = true - return res -} diff --git a/src/lsp/util/lexers.ts b/src/lsp/util/lexers.ts deleted file mode 100644 index 65197b943a3ef18cb7b5ab1435c10235bca67bbe..0000000000000000000000000000000000000000 --- a/src/lsp/util/lexers.ts +++ /dev/null @@ -1,53 +0,0 @@ -import moo from 'moo' -import { lazy } from './lazy' - -const classAttributeStates: { [x: string]: moo.Rules } = { - doubleClassList: { - lbrace: { match: /(? - moo.states({ - main: { - start1: { match: '"', push: 'doubleClassList' }, - start2: { match: "'", push: 'singleClassList' }, - start3: { match: '{', push: 'interp' }, - }, - ...classAttributeStates, - }) -) - -export const getComputedClassAttributeLexer = lazy(() => - moo.states({ - main: { - quote: { match: /['"{]/, push: 'interp' }, - }, - // TODO: really this should use a different interp definition that is - // terminated correctly based on the initial quote type - ...classAttributeStates, - }) -)