Skip to content

Commit

Permalink
[98] Hover modifications
Browse files Browse the repository at this point in the history
Use of unicode caracters for the hover service to show them into
tooltips

Signed-off-by: Vincent BLAIN <[email protected]>
  • Loading branch information
vblainobeo committed Oct 7, 2022
1 parent 5077667 commit c08b01c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
20 changes: 16 additions & 4 deletions plugins/fr.cea.nabla/src/fr/cea/nabla/LabelServices.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import fr.cea.nabla.nabla.Not
import fr.cea.nabla.nabla.Or
import fr.cea.nabla.nabla.Parenthesis
import fr.cea.nabla.nabla.Plus
import fr.cea.nabla.nabla.PrimitiveType
import fr.cea.nabla.nabla.RealConstant
import fr.cea.nabla.nabla.Reduction
import fr.cea.nabla.nabla.ReductionCall
Expand Down Expand Up @@ -160,7 +161,7 @@ class LabelServices
static def dispatch String getLabel(RealConstant it) { value.toString }
static def dispatch String getLabel(BoolConstant it) { value.toString }
static def dispatch String getLabel(MinConstant it) { '-\u221E' }
static def dispatch String getLabel(MaxConstant it) { '-\u221E' }
static def dispatch String getLabel(MaxConstant it) { '\u221E' }
static def dispatch String getLabel(FunctionCall it) { function.name + '(' + args.map[label].join(',') + ')' }
static def dispatch String getLabel(ReductionCall it) { reduction.name + '{' + iterationBlock?.label + '}(' + arg?.label + ')' }
static def dispatch String getLabel(BaseTypeConstant it) { type?.label + '(' + value?.label + ')' }
Expand All @@ -181,13 +182,24 @@ class LabelServices
}

/* TYPES *************************************************/

static def dispatch String getLabel(PrimitiveType it)
{
switch it
{
case REAL : '\u211D'
case INT : '\u2115'
case BOOL : '\u213E'
}
}

static def dispatch String getLabel(BaseType it)
{
if (sizes.empty)
primitive.literal
primitive.label
else if (sizes.forall[x | x instanceof IntConstant])
primitive.literal + sizes.map[x | IrUtils.getUtfExponent((x as IntConstant).value)].join('\u02E3')
primitive.label + sizes.map[x | IrUtils.getUtfExponent((x as IntConstant).value)].join('\u02E3')
else
primitive.literal + '[' + sizes.map[label].join(',') + ']'
primitive.label + '[' + sizes.map[label].join(',') + ']'
}
}
37 changes: 30 additions & 7 deletions plugins/fr.cea.nabla/src/fr/cea/nabla/hover/HoverHelper.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*******************************************************************************/
package fr.cea.nabla.hover

import com.google.inject.Inject
import fr.cea.nabla.LabelServices
import fr.cea.nabla.nabla.ArgOrVar
import fr.cea.nabla.nabla.BaseType
Expand All @@ -17,11 +18,11 @@ import fr.cea.nabla.nabla.Function
import fr.cea.nabla.nabla.Instruction
import fr.cea.nabla.nabla.Job
import fr.cea.nabla.nabla.NablaRoot
import fr.cea.nabla.nabla.Reduction
import fr.cea.nabla.typing.ArgOrVarTypeProvider
import fr.cea.nabla.typing.BaseTypeTypeProvider
import fr.cea.nabla.typing.ExpressionTypeProvider
import org.eclipse.emf.ecore.EObject
import com.google.inject.Inject

/**
* Helper class used to gather common methods for implementing hover services in both RCP and LSP implementation
Expand All @@ -39,7 +40,8 @@ class HoverHelper
{
Expression,
ArgOrVar,
Function: o
Function,
Reduction: o
NablaRoot,
Job,
Instruction: null
Expand All @@ -59,18 +61,39 @@ class HoverHelper
{
Expression: LabelServices.getLabel(o)
ArgOrVar: o.name
Function: o.name + '(' + o.intypesDeclaration.map[inTypes.typeText].join(', ') + ')'
Reduction: o.name.reductionName + '(' + o.typeDeclaration.type.typeText + ')'
Function: o.name.functionName + '(' + o.intypesDeclaration.map[inTypes.typeText].join(', ') + ')'
}
}

private static def String getFunctionName(String name)
{
switch (name)
{
case 'sqrt': '\u221A'
default: name
}
}

private static def String getReductionName(String name)
{
switch (name)
{
case 'sum': '\u2211'
case 'prod': '\u220F'
default: name
}
}

def String getTypeText(EObject o)
{
switch o
{
Expression: o.typeFor?.label
ArgOrVar: o.typeFor?.label
Function: o.returnTypeDeclaration.returnType?.typeFor?.label
BaseType: o.typeFor?.label
Expression: LabelServices.getLabel(o.typeFor?.primitive)
ArgOrVar: LabelServices.getLabel(o.typeFor?.primitive)
Function: o.returnTypeDeclaration.returnType?.typeFor?.label.replace(o.returnTypeDeclaration.returnType?.typeFor?.primitive.toString, LabelServices.getLabel(o.returnTypeDeclaration.returnType?.typeFor?.primitive))
Reduction: o.typeDeclaration.type?.typeFor?.label.replace(o.typeDeclaration.type?.typeFor?.primitive.toString, LabelServices.getLabel(o.typeDeclaration.type?.typeFor?.primitive))
BaseType: o.typeFor?.label.replace(o.typeFor?.primitive.toString, LabelServices.getLabel(o.typeFor?.primitive))
}
}
}

0 comments on commit c08b01c

Please sign in to comment.