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

Improve intellisense completions with complex qualifiers #7829

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 18 additions & 3 deletions webapp/src/monaco.tsx
Expand Up @@ -124,10 +124,12 @@ class CompletionProvider implements monaco.languages.CompletionItemProvider {
// remove what precedes the "." in the full snippet.
// E.g. if the user is typing "mobs.", we want to complete with "spawn" (name) not "mobs.spawn" (qName)
if (completions.isMemberCompletion && snippet) {
const nameStart = snippet.lastIndexOf(name);
if (nameStart !== -1) {
snippet = snippet.substr(nameStart)
let snippetQualifiers = getQualifiers(snippet);
if (qName.indexOf("anyButton") >= 0) {
console.log("snippet");
console.dir({ snippet, snippetQualifiers })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: cleanup

}
snippet = snippet.substr(snippetQualifiers.join('.').length + 1)
}
}
const label = completions.isMemberCompletion ? name : qName
Expand Down Expand Up @@ -168,6 +170,19 @@ class CompletionProvider implements monaco.languages.CompletionItemProvider {
function tosort(i: number): string {
return ("000" + i).slice(-4);
}
function getQualifiers(str: string): string[] {
if (!str) return []
const parts = str.split('.')
parts.pop() // the last part is never a qualifier
const isValidName = (s: string) => s.match(/^[a-zA-Z_$][0-9a-zA-Z_$]*$/)
let quals: string[] = [];
for (let p of parts) {
if (!isValidName(p))
break;
quals.push(p)
}
return quals;
}
}
/**
* Given a completion item fill in more data, like [doc-comment](#CompletionItem.documentation)
Expand Down