langium icon indicating copy to clipboard operation
langium copied to clipboard

Centralize template string functionality

Open danieldietrich opened this issue 4 years ago • 4 comments

Story

As a maintainer I want to keep application logic in a central place. The vscode extension should use core template string functionality to calculate indentation of template strings.

Acceptance criteria

  • [ ] the entry point of the core package only exports the tagged template s.
  • [ ] the core/generator package exports the internal functionality to compute template string indentation
  • [ ] the vscode-extension package uses the internal indentation functionality of the sub-module core/generator

danieldietrich avatar Mar 08 '21 15:03 danieldietrich

I stumbled upon one issue: I need to find strings within strings in order to nested highlight whitespace.

Here is an Xtend example:

whitespace detection

Langium example (whitespace = XXX + javascript code other than string contents):

const generated = s```
XXXclass A {
XXXXXX${members.map(member => {
XXXXXXXXXswtichX(member.type)X{
XXXXXXXXXXXXcaseX'method':XreturnXs```
XXXXXXXXXXXXXXXTODO: generate method
XXXXXXXXXXXX```
XXXXXXXXX}
XXXXXX}
XXX}

I do not have access to the AST (because it lives in the language server and the whitespace highlighter extension only has access to the editor contents), so I plan to implement a 'stack' parser that is aware of

  1. comments (in order to skipt strings within comments)
  2. strings (in order to find whitespace and align contents)
  3. template literal substitutions (in order to recurse in javascript code from within a string context)

danieldietrich avatar May 12 '21 07:05 danieldietrich

The changes in #825 break the highlighting provided by our vscode extension. @danieldietrich how shall we proceed with this? Remove the functionality for now, or make it work with the new API?

spoenemann avatar Dec 14 '22 13:12 spoenemann

@spoenemann could you please elaborate on the highlighting error by providing a screenshot? Let's see if there is a quick workaround...

danieldietrich avatar Dec 14 '22 14:12 danieldietrich

It just doesn't show any whitespace highlighting. I assume it's because the s function has been replaced by two functions expandToString and expandToNode?

spoenemann avatar Dec 14 '22 14:12 spoenemann