Skip to content
This repository was archived by the owner on Nov 21, 2025. It is now read-only.
This repository was archived by the owner on Nov 21, 2025. It is now read-only.

autocomplete doesnot work for variable with underscore(_) inside interface #258

Closed

Description

@sachinGAcharya

I am using Visual Studio Code for Angular 5 project I have converted my post JSON data into typeScript file like

//interface class of post data
export interface Client {
ctm_id: number;
firstname: string;
middlename: string;
}

//interface class of post data
export interface ClientContact {
phone: number;
alternate_phone: number;
}

//interface class of post data
export interface ClientPostData {
client: Client;
clientContacts: ClientContact;
clientMedical_info:Clientmedicalinfo;
}

// and declared in component class like
export class FormComponent implements OnInit {
public model: ClientPostData = {};
public ffirst_name:string;
}
I have installed Angular language service to get suggestions for variables from the interface.

When I type f it suggests firstname in html.but it doesn't suggest clientMedical_info when I type model.(dot).It suggests model.clients and model.clientContacts

How can I get suggestion of client_contact when I type model.(dot)

Activity

  1. ndtien84 commented on Jul 14, 2018

    @ndtien84

    I got same issue.

  2. olivermuc commented on Aug 10, 2018

    @olivermuc

    I accidentally posted the same issue here: microsoft/vscode#56077
    I case you need another example.

  3. olivermuc commented on Aug 10, 2018

    @olivermuc

    Could it be related to this line:

    const wordRe = /(\w|\(|\)|\[|\]|\*|\-|\_|\.)+/g;

  4. olivermuc commented on Aug 14, 2018

    @olivermuc

    No updates on this?

  5. NitashEU commented on Jan 15, 2019

    @NitashEU

    I have the exact same issue.

    On the template, the properties with underscore don't get suggested.

  6. minomikula commented on Jan 16, 2019

    @minomikula

    I have same issue. I tried to investigate.

    Problem is probably caused by using deprecated field CompletionItem.textEdit
    https://code.visualstudio.com/api/references/vscode-api#CompletionItem

    The commit 63db792 introduced using textEdit.

    I tried to find workaround, but in fact I don't know what exactly was use case for that commit. Only comment there is "improve text insertion for attributes". It tries somehow improve insertion of suggestions with special characters, and if it detects special char, it will use deprecated textEdit and suggestion will not appear.

    If someone could clarify the meaning on this commit, I could prepare PR. But right now possible solution could also be to remove this commit.

  7. olivermuc commented on Jan 16, 2019

    @olivermuc

    ..."improve text insertion for attributes"

    Well, I guess the intent was to provide some sanity checking to the auto completion logic.
    Unfortunately, it appears they went too restrictive.

    As I wrote above #258 (comment) , I tinkered with that expression a bit but really couldn't make it work at all.

    Rolling back the entire commit sounds harsh, but if that fixes it (or puts it back in a state that works for us) why not?!

    Let me know if there is anything I can help with re: Pull Request - QA / test etc.
    I can't own the PR but happy to support this!

  8. olivermuc commented on Jan 16, 2019

    @olivermuc

    Addendum: I found a workaround to make it work.

    First if the disclaimer: THIS IS THE UGLIEST HACK POSSIBLE, now on the bright side, it brings back all attributes, including ones with underscores and dashes.

    It's really all about commenting out this line:

    return TextEdit.replace(range, insertText);

    The any|void I simply added to appease TS lint during the vsix compilation.

    // Convert attribute names with non-\w chracters into a text edit.
    function insertionToEdit(range: Range, insertText: string): any | void {
      if (insertText.match(special) && range) {
        // return TextEdit.replace(range, insertText);
      }
    }
    

    PS: Thanks @minomikula for making take another stab at it.

  9. ednjv commented on Jan 31, 2019

    @ednjv

    Same issue here

  10. Meligy commented on Feb 27, 2019

    @Meligy

    It's really all about commenting out this line:

    vscode-ng-language-service/server/src/server.ts

    Line 97 in f5e2317

     return TextEdit.replace(range, insertText);

    Based on that file, it might also be correct that the actual fix is removing _ from:

    const special = /\(|\)|\[|\]|\*|\-|\_|\./;

  11. olivermuc commented on Mar 6, 2019

    @olivermuc

    It's really all about commenting out this line:
    vscode-ng-language-service/server/src/server.ts
    Line 97 in f5e2317

     return TextEdit.replace(range, insertText);

    Based on that file, it might also be correct that the actual fix is removing _ from:

    vscode-ng-language-service/server/src/server.ts
    Line 92 in f5e2317
    const special = /(|)|[|]|*|-|_|./;

    It seems like the logical place to make the change, but for whatever reason this did not fix it for me, I tried.

  12. myml commented on Mar 6, 2019

    @myml

    Same issue here

  13. afonsoma9 commented on May 23, 2019

    @afonsoma9

    Same issue here

  14. jgraffin commented on Jun 26, 2019

    @jgraffin

    Same issue here! Any workaround to resolve this?

  15. viiskies commented on Jul 22, 2019

    @viiskies

    Same

  16. kyliau commented on Nov 8, 2019

    @kyliau
    Contributor

    @ayazhafiz fixed this in angular/angular#33091

    For reference, this is how the word boundary was determined before:

    function getReplaceRange(document: lsp.TextDocumentIdentifier, offset: number): lsp.Range {
    const line = documents.getDocumentLine(document, offset);
    if (line && line.text && line.start <= offset && line.start + line.text.length >= offset) {
    const lineOffset = offset - line.start - 1;
    // Find the word that contains the offset
    let found: number, len: number;
    line.text.replace(wordRe, <any>((word: string, _: string, wordOffset: number) => {
    if (wordOffset <= lineOffset && wordOffset + word.length >= lineOffset && word.match(special)) {
    found = wordOffset;
    len = word.length;
    }
    }));
    if (found != null) {
    return lsp.Range.create(line.line - 1, found, line.line - 1, found + len);
    }
    }
    }

    Starting from v0.900.0, the replacement span is determined by looking at the proper AST.

  17. angular-automatic-lock-bot commented on Feb 17, 2020

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  18. locked and limited conversation to collaborators on Feb 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions