mirror of
https://github.com/adelphes/android-dev-ext.git
synced 2025-12-23 09:59:25 +00:00
add support for field and method docs
This commit is contained in:
@@ -377,6 +377,7 @@ function getTypedNameCompletion(typemap, type_signature, opts, typelist) {
|
|||||||
*/
|
*/
|
||||||
function shouldInclude(modifiers, t) {
|
function shouldInclude(modifiers, t) {
|
||||||
if (opts.statics !== modifiers.includes('static')) return;
|
if (opts.statics !== modifiers.includes('static')) return;
|
||||||
|
if (modifiers.includes('abstract')) return;
|
||||||
if (modifiers.includes('public')) return true;
|
if (modifiers.includes('public')) return true;
|
||||||
if (modifiers.includes('protected')) return true;
|
if (modifiers.includes('protected')) return true;
|
||||||
if (modifiers.includes('private') && t === type) return true;
|
if (modifiers.includes('private') && t === type) return true;
|
||||||
@@ -388,8 +389,8 @@ function getTypedNameCompletion(typemap, type_signature, opts, typelist) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getTypeInheritanceList(type).forEach((t,idx) => {
|
getTypeInheritanceList(type).forEach((t,idx) => {
|
||||||
t.fields.sort(sortByName).filter(f => shouldInclude(f.modifiers, t)).forEach(f => fields.set(f.name, {f, sortText: `${idx+100}${f.name}`}));
|
t.fields.sort(sortByName).filter(f => shouldInclude(f.modifiers, t)).forEach(f => fields.set(f.name, {f, t, sortText: `${idx+100}${f.name}`}));
|
||||||
t.methods.sort(sortByName).filter(f => shouldInclude(f.modifiers, t)).forEach(m => methods.set(m.methodSignature, {m, sortText: `${idx+100}${m.name}`}));
|
t.methods.sort(sortByName).filter(f => shouldInclude(f.modifiers, t)).forEach(m => methods.set(m.methodSignature, {m, t, sortText: `${idx+100}${m.name}`}));
|
||||||
});
|
});
|
||||||
|
|
||||||
const subtype_search = type.shortSignature + '$';
|
const subtype_search = type.shortSignature + '$';
|
||||||
@@ -401,7 +402,6 @@ function getTypedNameCompletion(typemap, type_signature, opts, typelist) {
|
|||||||
return {
|
return {
|
||||||
label: t.slice(subtype_search.length).replace(/\$/g,'.'),
|
label: t.slice(subtype_search.length).replace(/\$/g,'.'),
|
||||||
kind: CompletionItemKind.Class,
|
kind: CompletionItemKind.Class,
|
||||||
data: -1,
|
|
||||||
}
|
}
|
||||||
}).filter(x => x),
|
}).filter(x => x),
|
||||||
// fields
|
// fields
|
||||||
@@ -410,7 +410,7 @@ function getTypedNameCompletion(typemap, type_signature, opts, typelist) {
|
|||||||
insertText: f.f.name,
|
insertText: f.f.name,
|
||||||
kind: CompletionItemKind.Field,
|
kind: CompletionItemKind.Field,
|
||||||
sortText: f.sortText,
|
sortText: f.sortText,
|
||||||
data: -1,
|
data: { type: f.t.shortSignature, fidx: f.t.fields.indexOf(f.f) },
|
||||||
})),
|
})),
|
||||||
// methods
|
// methods
|
||||||
...[...methods.values()].map(m => ({
|
...[...methods.values()].map(m => ({
|
||||||
@@ -418,7 +418,7 @@ function getTypedNameCompletion(typemap, type_signature, opts, typelist) {
|
|||||||
kind: CompletionItemKind.Method,
|
kind: CompletionItemKind.Method,
|
||||||
insertText: m.m.name,
|
insertText: m.m.name,
|
||||||
sortText: m.sortText,
|
sortText: m.sortText,
|
||||||
data: -1,
|
data: { type: m.t.shortSignature, midx: m.t.methods.indexOf(m.m) },
|
||||||
}))
|
}))
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -587,7 +587,7 @@ connection.onCompletion(
|
|||||||
({
|
({
|
||||||
label: t.dottedTypeName,
|
label: t.dottedTypeName,
|
||||||
kind: typeKindMap[t.typeKind],
|
kind: typeKindMap[t.typeKind],
|
||||||
data: t.shortSignature,
|
data: {type:t.shortSignature},
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
...getRootPackageCompletions()
|
...getRootPackageCompletions()
|
||||||
@@ -603,18 +603,38 @@ connection.onCompletionResolve(
|
|||||||
* @param {CompletionItem} item
|
* @param {CompletionItem} item
|
||||||
*/
|
*/
|
||||||
(item) => {
|
(item) => {
|
||||||
|
item.detail = item.documentation = '';
|
||||||
if (androidLibrary instanceof Promise) {
|
if (androidLibrary instanceof Promise) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
const t = androidLibrary.get(item.data);
|
if (typeof item.data !== 'object') {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
const t = androidLibrary.get(item.data.type);
|
||||||
|
const field = t && t.fields[item.data.fidx];
|
||||||
|
const method = t && t.methods[item.data.midx];
|
||||||
if (!t) {
|
if (!t) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
item.detail = t.fullyDottedRawName;
|
let detail, documentation, header;
|
||||||
item.documentation = t.docs && {
|
if (field) {
|
||||||
|
detail = field.label;
|
||||||
|
documentation = field.docs;
|
||||||
|
header = `${field.type.simpleTypeName} **${field.name}**`;
|
||||||
|
} else if (method) {
|
||||||
|
detail = `${method.modifiers.join(' ')} ${t.simpleTypeName}.${method.name}`;
|
||||||
|
documentation = method.docs;
|
||||||
|
header = method.shortlabel.replace(/^\w+/, x => `**${x}**`).replace(/^(.+?)\s*:\s*(.+)/, (_,a,b) => `${b} ${a}`);
|
||||||
|
} else {
|
||||||
|
detail = t.fullyDottedRawName,
|
||||||
|
documentation = t.docs,
|
||||||
|
header = `${t.typeKind} **${t.dottedTypeName}**`;
|
||||||
|
}
|
||||||
|
item.detail = detail || '';
|
||||||
|
item.documentation = documentation && {
|
||||||
kind: 'markdown',
|
kind: 'markdown',
|
||||||
value: `${t.typeKind} **${t.dottedTypeName}**\n\n${
|
value: `${header}\n\n${
|
||||||
t.docs
|
documentation
|
||||||
.replace(/(<p ?.*?>)|(<\/?i>|<\/?em>)|(<\/?b>|<\/?strong>|<\/?dt>)|(<\/?tt>)|(<\/?code>|<\/?pre>)|(\{@link.+?\}|\{@code.+?\})|(<li>)|(<a href="\{@docRoot\}.*?">.+?<\/a>)|(<h\d>)|<\/?dd ?.*?>|<\/p ?.*?>|<\/h\d ?.*?>|<\/?div ?.*?>|<\/?[uo]l ?.*?>/gim, (_,p,i,b,tt,c,lc,li,a,h) => {
|
.replace(/(<p ?.*?>)|(<\/?i>|<\/?em>)|(<\/?b>|<\/?strong>|<\/?dt>)|(<\/?tt>)|(<\/?code>|<\/?pre>)|(\{@link.+?\}|\{@code.+?\})|(<li>)|(<a href="\{@docRoot\}.*?">.+?<\/a>)|(<h\d>)|<\/?dd ?.*?>|<\/p ?.*?>|<\/h\d ?.*?>|<\/?div ?.*?>|<\/?[uo]l ?.*?>/gim, (_,p,i,b,tt,c,lc,li,a,h) => {
|
||||||
return p ? '\n\n'
|
return p ? '\n\n'
|
||||||
: i ? '*'
|
: i ? '*'
|
||||||
|
|||||||
Reference in New Issue
Block a user