Skip to content

Commit

Permalink
Single comments added
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Jan 4, 2025
1 parent d35b837 commit 0016ec4
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 179 deletions.
40 changes: 18 additions & 22 deletions packages/client/src/highlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@
import * as vscode from 'vscode'
import { excludeNullish, parse } from 'wollok-ts'
import { WollokNodePlotter, WollokPosition } from './highlighter/utils'
import { processCode, processComments } from './highlighter/tokenProvider'
import { processCode } from './highlighter/tokenProvider'
import { tokenModifiers, tokenTypes } from './highlighter/definitions'

const convertToVSCPosition = (position: WollokPosition) =>
new vscode.Position(position.line, position.column)

const convertToVSCTokens = (wollokNodesPlotter: WollokNodePlotter[]) =>
wollokNodesPlotter
.map(wollokNodePlotter => {
const { range } = wollokNodePlotter
const { start, end } = range
return {
...wollokNodePlotter,
range: new vscode.Range(
convertToVSCPosition(start),
convertToVSCPosition(end),
),
}
})
const convertToVSCToken = (wollokNodePlotter: WollokNodePlotter) => {
const { range } = wollokNodePlotter
const { start, end } = range
return {
...wollokNodePlotter,
range: new vscode.Range(
convertToVSCPosition(start),
convertToVSCPosition(end),
),
}
}

export const provider: vscode.DocumentSemanticTokensProvider = {
provideDocumentSemanticTokens(
Expand All @@ -30,17 +28,15 @@ export const provider: vscode.DocumentSemanticTokensProvider = {
const parsedFile = parse.File(document.fileName)
const textFile = document.getText()
const parsedPackage = parsedFile.tryParse(textFile)
const packageNode = parsedPackage.members[0]

const splittedLines = textFile.split('\n')
const processed = excludeNullish([]
.concat(convertToVSCTokens(processCode(parsedPackage.members[0], splittedLines)))
.concat(processComments(splittedLines))
)

processed.forEach((node: WollokNodePlotter) =>
tokensBuilder.push(node.range as unknown as vscode.Range, node.tokenType, node.tokenModifiers)
)
const processed = excludeNullish(processCode(packageNode, splittedLines))

processed.forEach((node: WollokNodePlotter) => {
const vscToken = convertToVSCToken(node)
tokensBuilder.push(vscToken.range as unknown as vscode.Range, vscToken.tokenType, vscToken.tokenModifiers)
})
return tokensBuilder.build()
},
}
Expand Down
20 changes: 15 additions & 5 deletions packages/client/src/highlighter/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,36 @@ export const tokenTypes = [
'variable', // For identifiers that declare or reference a local or global variable.
]

export function plotter(start: { ln, col, len }, kind: string): WollokNodePlotter {
export function plotSingleLine(start: { ln, col, len }, kind: string): WollokNodePlotter {
return {
range: createRange(start.ln, start.col, start.len),
tokenType: tokenTypeObj[kind],
tokenModifiers: ['declaration'],
}
}

export function plotMultiline(start: { ln, col }, end: { ln, col }, kind: string): WollokNodePlotter {
return {
range: createRange(start.ln, start.col, start.len),

Check failure on line 125 in packages/client/src/highlighter/definitions.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, lts/hydrogen)

Property 'len' does not exist on type '{ ln: any; col: any; }'.

Check failure on line 125 in packages/client/src/highlighter/definitions.ts

View workflow job for this annotation

GitHub Actions / test (macos-latest, lts/hydrogen)

Property 'len' does not exist on type '{ ln: any; col: any; }'.
tokenType: tokenTypeObj[kind],
tokenModifiers: ['declaration'],
}
}
/*
Standard token modifiers:
ID Description
Standard token modifiers
ID Description
----------------------------------------------------------------------------------------------
declaration For declarations of symbols.
definition For definitions of symbols, for example, in header files.
readonly For readonly variables and member fields (constants).
static For class members (static members).
static For class members (static members).
deprecated For symbols that should no longer be used.
abstract For types and member functions that are abstract.
async For functions that are marked async.
async For functions that are marked async.
modification For variable references where the variable is assigned to.
documentation For occurrences of symbols in documentation.
defaultLibrary For symbols that are part of the standard library.
*/
Loading

0 comments on commit 0016ec4

Please sign in to comment.