Reputation: 4760
I am writing my first VSCode extension and can’t find an example on how I create autocompletion for objects that I define in my extension. For example, I might have a class like this:
class Foo {
public aMemberVar = 'aMemberVar Member Variable';
public aFuncName = 'aMemberFunc';
public settings = {
display: {
alignment: 'left',
height: 100,
width: 100,
theme: {
on: true,
color: 'blue'
}
}
}
function aMemberFunc() {
print 'Inside `aMemberFunc()`';
}
}
Now, I want a user that has my extension installed to be able to start typing Foo. and automatically VSCode will show him the methods and keys on this class.
I have created a typescript definition for this like so:
interface IFoo {
aMemberVar: string;
aFuncName: string;
settings: {
display: {
alignment: string;
height: number;
width: number;
theme: {
on: boolean;
color: string;
};
};
};
aMemberFunc(): void;
}
Now my extension is not for typescript, but for a different language, so how do I show autocompletion, in files other than typescript?
Upvotes: 1
Views: 2593
Reputation: 53307
You have to write and register a CompletionItemProvider. In that provider you have to use a tool that can give you completion candidates. Some extensions use external tools which can provide that info, others do all the heavy lifting themselves by parsing the available sources and creating a symbol table that provides all required symbol informations.
Upvotes: 1