OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Can the Monaco Editor use different line numbering based on the model?

  • Thread starter Thread starter Matt Lacey
  • Start date Start date
M

Matt Lacey

Guest
I'm using the Monaco Editor to display some custom file types.
For these files, I need to customize the displayed line numbers based on the models. This is fine for a single model but not when I want to peek to the definition in another model/file. (For the content, the displayed line numbers don't always start at the same number and some physical lines in the file don't count as a line and so shouldn't have a line number displayed next to them.)

I'm setting the custom line numbers as per the example at https://microsoft.github.io/monaco-...-with-the-editor-customizing-the-line-numbers

This lineNumbersFunc is always the same for every file/model that is displayed, but that's not what I want.

Is there another way to specify the line numbers? (based on models)
or
Is there a way to get the model that the line number relates to in lineNumbersFunc?

I've tried using editor.getModel() inside the function but this always returns the initial model, not the one being shown in the inline/peeked view.

--- edit ---

See an example of what I'm trying to do in the playground

It produces this when the code lens is clicked Image showing other file/model being peeked but with the wrong line numbering

<p>I'm using the Monaco Editor to display some custom file types.<br />
For these files, I need to customize the displayed line numbers based on the models. This is fine for a single model but not when I want to peek to the definition in another model/file. (For the content, the displayed line numbers don't always start at the same number and some physical lines in the file don't count as a line and so shouldn't have a line number displayed next to them.)</p>
<p>I'm setting the custom line numbers as per the example at <a href="https://microsoft.github.io/monaco-...-with-the-editor-customizing-the-line-numbers" rel="nofollow noreferrer">https://microsoft.github.io/monaco-...-with-the-editor-customizing-the-line-numbers</a></p>
<p>This <code>lineNumbersFunc</code> is always the same for every file/model that is displayed, but that's not what I want.</p>
<p><strong>Is there another way to specify the line numbers? (based on models)</strong><br />
or<br />
<strong>Is there a way to get the model that the line number relates to in <code>lineNumbersFunc</code>?</strong></p>
<p>I've tried using <code>editor.getModel()</code> inside the function but this always returns the initial model, not the one being shown in the inline/peeked view.</p>
<p>--- edit ---</p>
<p>See an <a href="https://microsoft.github.io/monaco-...yv4fHWwNX4kIZ-qy1y8JqTIDg5izxCW8OtG0QJv85vFAA" rel="nofollow noreferrer">example of what I'm trying to do in the playground</a></p>
<p>It produces this when the code lens is clicked
<a href="https://i.sstatic.net/0g5PlsCY.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/0g5PlsCY.png" alt="Image showing other file/model being peeked but with the wrong line numbering" /></a></p>
 

Latest posts

A
Replies
0
Views
1
AgencyAnalytics
A
S
Replies
0
Views
1
Stacker Media
S
C
Replies
0
Views
1
CC.Talent
C
Top