monaco-languageclient icon indicating copy to clipboard operation
monaco-languageclient copied to clipboard

Support for expressions

Open alexgoaga opened this issue 1 year ago • 4 comments

Hi,

I would like to be able to write a a C# expression in a monaco editor and prepend, append the corresponding code.

Instead of writing all these code in a monaco editor:

using System;

namespace MyApp { class Program { static void Main(string[] args) { var str = "abcdef"; str = str.Replace("/", "").Replace("&", "") } } }

I would like to write only

str.Replace("/", "").Replace("&", "")

then intercept the message going to LSP and prepend, append the corresponding code above.(provide the context for the expression)

Is there a way to intercept and adjust the messages?

Thanks, Alex.

alexgoaga avatar Feb 14 '24 19:02 alexgoaga

You'll need to hack plenty of stuff to achieve exactly what you describe, I'm not sure it's even doable but it's sure it's very hard

Your best chance is to put the whole file in the editor, but just hiding the part you don't want to display

CGNonofr avatar Feb 14 '24 19:02 CGNonofr

I looked into hiding some of the code, but I couldn't find anything in monaco. Any suggestions will be appreciated.

alexgoaga avatar Feb 14 '24 19:02 alexgoaga

The only way is by hacking the folding feature, you can have a look at https://github.com/CodinGame/monaco-editor-wrapper/blob/main/src/tools.ts

you can use the hideCodeWithoutDecoration function:

editor.createDecorationsCollection().set([{
  range: <the visible range>,
  options: {
     className: 'displayed',
     isWholeLine: true
  }
}])
hideCodeWithoutDecoration(
    editor,
   (decoration) => decoration.options.className === 'displayed'
)

CGNonofr avatar Feb 14 '24 19:02 CGNonofr

Checking.

Thanks.

alexgoaga avatar Feb 14 '24 19:02 alexgoaga

@alexgoaga I am closing this, because it is not an issue. If you have a new question don't hesitate to open a discussion. Thanks.

kaisalmen avatar Mar 13 '24 13:03 kaisalmen