question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

insertText() not working for namespace

See original GitHub issue

Version: 14.4.2

index.d.ts file contents:

   export {}
  
   declare global {
    export interface Person { name: string }
    export type People = Person[]
   }

Code I’m using to insert new interface into global namespace:

const globalNode = definitionsFile.getNamespace('global')
if (!globalNode) throw new Error('globalNode not found')

globalNode.insertText(globalNode.getEnd(), 'export interface Car { model: string }')

Expected: new interface to be inserted

Actual: Error thrown: “Cannot insert or replace text outside the bounds of the node. Expected a position between [36, 41], but received 42.”

I also tried to use globalNode.getEnd() -1 - it just gives different error. FYI, just checked, if global namespace is empty (no declared interfaces or types), it also gives this error, just with different position number.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dsherretcommented, Sep 7, 2018

Fixed in 14.4.3.

1reaction
dsherretcommented, Sep 6, 2018

@ihorskyi I just tried this out and you’re right that this wasn’t working properly! It should just be by doing -1 to go to the left of the close brace like you said.

It’s a little difficult because you have to handle the spacing yourself:

globalNode.insertText(globalNode.getEnd() - 1, writer => {
    writer.indent().write('export interface Car { model: string }').newLine();
});

That doesn’t work right now, but it will be working in the next release. Thanks for reporting this!

Read more comments on GitHub >

github_iconTop Results From Across the Web

CommandField.InsertText Property - Microsoft Learn
The following code example demonstrates how to use the InsertText property to specify a custom caption for an Insert button displayed in a...
Read more >
SubDocument.InsertText(DocumentPosition, String) Method
SubDocument.InsertText(DocumentPosition, String) Method ... Inserts the specified text at the specified position. Namespace: DevExpress.XtraRichEdit.API.Native.
Read more >
c# - Insert text at cursor position - Stack Overflow
I need to insert text from a variable at the cursor position no matter in which window/program it is located, so whenever the...
Read more >
What to do if insertText doesn't work, but there are no error ...
I'm trying to add text to an image I have but the insertText function isn't working. No errors show up when I run...
Read more >
clang::Rewriter Class Reference
InsertText - Insert the specified string at the specified location in the original ... Referenced by clang::arcmt::MigrationProcess::applyTransform(), ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found