TypeFox / monaco-languageclient

Repo hosts npm packages for monaco-languageclient, vscode-ws-jsonrpc, monaco-editor-wrapper, @typefox/monaco-editor-react and monaco-languageclient-examples
https://www.npmjs.com/package/monaco-languageclient
MIT License
1.06k stars 177 forks source link

Support for expressions #603

Closed alexgoaga closed 7 months ago

alexgoaga commented 8 months ago

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.

CGNonofr commented 8 months ago

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

alexgoaga commented 8 months ago

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

CGNonofr commented 8 months ago

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'
)
alexgoaga commented 8 months ago

Checking.

Thanks.

kaisalmen commented 7 months ago

@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.