Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sachinGAcharya opened this issue Jun 4, 2018 · 17 comments
Assignees

Comments

@sachinGAcharya
Copy link

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)

@ndtien84
Copy link

I got same issue.

@olivermuc
Copy link

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

@olivermuc
Copy link

Could it be related to this line:

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

@olivermuc
Copy link

No updates on this?

@NitashEU
Copy link

I have the exact same issue.

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

@minomikula
Copy link

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.

@olivermuc
Copy link

..."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!

@olivermuc
Copy link

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.

@ednjv
Copy link

ednjv commented Jan 31, 2019

Same issue here

@Meligy
Copy link

Meligy commented Feb 27, 2019

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 = /\(|\)|\[|\]|\*|\-|\_|\./;

@olivermuc
Copy link

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.

@myml
Copy link

myml commented Mar 6, 2019

Same issue here

1 similar comment
@afonsoma9
Copy link

Same issue here

@jgraffin
Copy link

Same issue here! Any workaround to resolve this?

@viiskies
Copy link

Same

@kyliau
Copy link
Contributor

kyliau commented Nov 8, 2019

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

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests