diff --git a/packages/client/src/highlighter.ts b/packages/client/src/highlighter.ts index ac629d9..4936ec3 100644 --- a/packages/client/src/highlighter.ts +++ b/packages/client/src/highlighter.ts @@ -10,10 +10,6 @@ const convertToVSCPosition = (position: WollokPosition) => const convertToVSCTokens = (wollokNodesPlotter: WollokNodePlotter[]) => wollokNodesPlotter - .filter(wollokNodePlotter => { - const { range } = wollokNodePlotter - return !!range && range.start && range.end - }) .map(wollokNodePlotter => { const { range } = wollokNodePlotter const { start, end } = range @@ -38,7 +34,8 @@ export const provider: vscode.DocumentSemanticTokensProvider = { const splittedLines = textFile.split('\n') const processed = excludeNullish([] .concat(convertToVSCTokens(processCode(parsedPackage.members[0], splittedLines))) - .concat(processComments(splittedLines))) + .concat(processComments(splittedLines)) + ) processed.forEach((node: WollokNodePlotter) => tokensBuilder.push(node.range as unknown as vscode.Range, node.tokenType, node.tokenModifiers) diff --git a/packages/client/src/highlighter/tokenProvider.ts b/packages/client/src/highlighter/tokenProvider.ts index 612b8f0..042a1e0 100644 --- a/packages/client/src/highlighter/tokenProvider.ts +++ b/packages/client/src/highlighter/tokenProvider.ts @@ -105,11 +105,14 @@ function processNode(node: Node, documentoStr: string[], context: NodeContext[]) if (node.sourceMap == undefined) return nullHighlighting const currentNode = node as unknown as NamedNode const validName = node.name !== undefined && node.name.trim().length - return { result: [ - !node.isClosure() ? defaultKeywordPlotter(node) : [], - node.supertypes.length ? keywordPlotter(node, KEYWORDS.INHERITS) : [], - validName ? generatePlotterForNode(currentNode) : [], - ], references: validName ? saveReference(currentNode) : undefined } + const result = [] + if (!node.isClosure()) result.push(defaultKeywordPlotter(node)) + if (node.supertypes.length) result.push(keywordPlotter(node, KEYWORDS.INHERITS)) + if (validName) result.push(generatePlotterForNode(currentNode)) + return { + result, + references: validName ? saveReference(currentNode) : undefined, + } }), when(Field)(node => node.isSynthetic ? nullHighlighting : resultForReference(node) diff --git a/packages/client/src/test/highlighter/inheritance.test.ts b/packages/client/src/test/highlighter/inheritance.test.ts index 7939d28..b0426e1 100644 --- a/packages/client/src/test/highlighter/inheritance.test.ts +++ b/packages/client/src/test/highlighter/inheritance.test.ts @@ -53,7 +53,6 @@ suite('inheritance sample', () => { }) test('highlights class names', () => { - console.info(JSON.stringify(processed.filter(t => t.tokenType === 'class'))) const keywordsTokens = processedByTokenType(processed, 'class') const nextRange = () => keywordsTokens.next().value.range diff --git a/packages/client/src/test/highlighter/utils.ts b/packages/client/src/test/highlighter/utils.ts index d486582..b4abf66 100644 --- a/packages/client/src/test/highlighter/utils.ts +++ b/packages/client/src/test/highlighter/utils.ts @@ -3,12 +3,20 @@ import { readFileSync } from 'fs' import { processCode, processComments } from '../../highlighter/tokenProvider' import { WollokNodePlotter } from '../../highlighter/utils' +const validateHighlighter = (wollokNodesPlotter: WollokNodePlotter[]) => + wollokNodesPlotter.every(wollokNodePlotter => { + const { range } = wollokNodePlotter + return !!range && range.start && range.end + }) + export const readFileForTokenProvider = (filePath: string): WollokNodePlotter[] => { const parsedFile = parse.File(filePath) const docText = readFileSync(filePath, { encoding: 'utf-8' }) const parsedPackage = parsedFile.tryParse(docText) const splittedLines = docText.split('\n') - return excludeNullish(processCode(parsedPackage.members[0], splittedLines)).concat(processComments(splittedLines)) + const processed = excludeNullish(processCode(parsedPackage.members[0], splittedLines)).concat(processComments(splittedLines)) + validateHighlighter(processed) + return processed } export const processedByTokenType = (processed: WollokNodePlotter[], tokenType: string): IterableIterator => processed.filter(token => token.tokenType === tokenType).values()