Skip to content

Commit

Permalink
Add named arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Jan 3, 2025
1 parent 7a45e56 commit ca75b13
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/client/src/highlighter/tokenProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Assignment, Class, Describe, Field, If, Import, KEYWORDS, last, Literal, match, Method, New, Node, Package, Parameter, Program, Reference, Return, Self, Send, Singleton, Super, Test, Throw, Try, Variable, when } from 'wollok-ts'
import { Assignment, Class, Describe, Field, If, Import, KEYWORDS, last, Literal, match, Method, NamedArgument, New, Node, Package, Parameter, Program, Reference, Return, Self, Send, Singleton, Super, Test, Throw, Try, Variable, when } from 'wollok-ts'
import { keywords, plotter, tokenTypeObj } from './definitions'
import { WollokNodePlotter } from './utils'

Expand Down Expand Up @@ -147,6 +147,11 @@ function processNode(node: Node, textDocument: string[], context: NodeContext[])
defaultKeywordPlotter(node),
], references: undefined,
})),
when(NamedArgument)(node => ({
result: [
generatePlotterForNode(node),
], references: undefined,
})),
when(Parameter)(node => {
const { line, column, word } = getLine(node, textDocument)
const col = column + word.indexOf(node.name)
Expand Down
12 changes: 12 additions & 0 deletions packages/client/src/test/highlighter/class.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ suite('a class sample', () => {
expect(birthdateDefinitionRange.start).toEqual({ line: 2, column: 15 })
expect(birthdateDefinitionRange.end).toEqual({ line: 2, column: 24 })

const dayNamedArgumentRange = nextRange()
expect(dayNamedArgumentRange.start).toEqual({ line: 2, column: 36 })
expect(dayNamedArgumentRange.end).toEqual({ line: 2, column: 39 })

const monthNamedArgumentRange = nextRange()
expect(monthNamedArgumentRange.start).toEqual({ line: 2, column: 45 })
expect(monthNamedArgumentRange.end).toEqual({ line: 2, column: 50 })

const yearNamedArgumentRange = nextRange()
expect(yearNamedArgumentRange.start).toEqual({ line: 2, column: 56 })
expect(yearNamedArgumentRange.end).toEqual({ line: 2, column: 60 })

const energyInFlyMethodRange1 = nextRange()
expect(energyInFlyMethodRange1.start).toEqual({ line: 5, column: 4 })
expect(energyInFlyMethodRange1.end).toEqual({ line: 5, column: 10 })
Expand Down
12 changes: 12 additions & 0 deletions packages/client/src/test/highlighter/inheritance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ suite('inheritance sample', () => {
const energyVarFromBirdRange = nextRange()
expect(energyVarFromBirdRange.start).toEqual({ line: 1, column: 6 })
expect(energyVarFromBirdRange.end).toEqual({ line: 1, column: 12 })

const energyAsNamedParameterRange = nextRange()
expect(energyAsNamedParameterRange.start).toEqual({ line: 5, column: 28 })
expect(energyAsNamedParameterRange.end).toEqual({ line: 5, column: 34 })

const energyAsNamedParameter2Range = nextRange()
expect(energyAsNamedParameter2Range.start).toEqual({ line: 7, column: 32 })
expect(energyAsNamedParameter2Range.end).toEqual({ line: 7, column: 38 })

const energyAsNamedParameter3Range = nextRange()
expect(energyAsNamedParameter3Range.start).toEqual({ line: 9, column: 38 })
expect(energyAsNamedParameter3Range.end).toEqual({ line: 9, column: 44 })
})

test('highlights global variables', () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/client/src/test/highlighter/program.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ suite('a program sample', () => {
expect(firstProgramDefinitionRange.start).toEqual({ line: 0, column: 8 })
expect(firstProgramDefinitionRange.end).toEqual({ line: 0, column: 12 })

const messageNamedArgumentForExceptionRange = nextRange()
expect(messageNamedArgumentForExceptionRange.start).toEqual({ line: 3, column: 40 })
expect(messageNamedArgumentForExceptionRange.end).toEqual({ line: 3, column: 47 })

const secondProgramDefinitionRange = nextRange()
expect(secondProgramDefinitionRange.start).toEqual({ line: 11, column: 8 })
expect(secondProgramDefinitionRange.end).toEqual({ line: 11, column: 19 })
Expand Down

0 comments on commit ca75b13

Please sign in to comment.