mirror of
https://github.com/adelphes/android-dev-ext.git
synced 2025-12-23 01:48:18 +00:00
support member completion for array types
improve comment formatting
This commit is contained in:
@@ -17,7 +17,7 @@ const {
|
|||||||
|
|
||||||
const { TextDocument } = require('vscode-languageserver-textdocument');
|
const { TextDocument } = require('vscode-languageserver-textdocument');
|
||||||
|
|
||||||
const { loadAndroidLibrary, JavaType, CEIType } = require('java-mti');
|
const { loadAndroidLibrary, JavaType, CEIType, ArrayType, PrimitiveType } = require('java-mti');
|
||||||
|
|
||||||
const { ParseProblem } = require('./java/parser');
|
const { ParseProblem } = require('./java/parser');
|
||||||
const { parse } = require('./java/body-parser3');
|
const { parse } = require('./java/body-parser3');
|
||||||
@@ -351,17 +351,28 @@ connection.onDidChangeWatchedFiles((_change) => {
|
|||||||
* @param {string[]} [typelist]
|
* @param {string[]} [typelist]
|
||||||
*/
|
*/
|
||||||
function getTypedNameCompletion(typemap, type_signature, opts, typelist) {
|
function getTypedNameCompletion(typemap, type_signature, opts, typelist) {
|
||||||
if (!/^L.+;/.test(type_signature)) {
|
let type, types, subtype_search;
|
||||||
return [];
|
const arr_match = type_signature.match(/^\[+/);
|
||||||
}
|
if (arr_match) {
|
||||||
const type = typemap.get(type_signature.slice(1,-1));
|
// for arrays, just create a dummy type
|
||||||
if (!type) {
|
types = [
|
||||||
|
type = new ArrayType(PrimitiveType.map.V, arr_match[0].length),
|
||||||
|
typemap.get('java/lang/Object'),
|
||||||
|
];
|
||||||
|
} else if (!/^L.+;/.test(type_signature)) {
|
||||||
return [];
|
return [];
|
||||||
|
} else {
|
||||||
|
type = typemap.get(type_signature.slice(1,-1));
|
||||||
|
if (!type) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
if (!(type instanceof CEIType)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
types = getTypeInheritanceList(type);
|
||||||
|
subtype_search = type.shortSignature + '$';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(type instanceof CEIType)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// add inner types, fields and methods
|
// add inner types, fields and methods
|
||||||
class FirstSetMap extends Map {
|
class FirstSetMap extends Map {
|
||||||
@@ -388,7 +399,7 @@ function getTypedNameCompletion(typemap, type_signature, opts, typelist) {
|
|||||||
return a.name.localeCompare(b.name, undefined, {sensitivity: 'base'})
|
return a.name.localeCompare(b.name, undefined, {sensitivity: 'base'})
|
||||||
}
|
}
|
||||||
|
|
||||||
getTypeInheritanceList(type).forEach((t,idx) => {
|
types.forEach((t,idx) => {
|
||||||
t.fields.sort(sortByName)
|
t.fields.sort(sortByName)
|
||||||
.filter(f => shouldInclude(f.modifiers, t))
|
.filter(f => shouldInclude(f.modifiers, t))
|
||||||
.forEach(f => fields.set(f.name, {f, t, sortText: `${idx+100}${f.name}`}));
|
.forEach(f => fields.set(f.name, {f, t, sortText: `${idx+100}${f.name}`}));
|
||||||
@@ -397,12 +408,10 @@ function getTypedNameCompletion(typemap, type_signature, opts, typelist) {
|
|||||||
.forEach(m => methods.set(`${m.name}${m.methodSignature}`, {m, t, sortText: `${idx+100}${m.name}`}));
|
.forEach(m => methods.set(`${m.name}${m.methodSignature}`, {m, t, sortText: `${idx+100}${m.name}`}));
|
||||||
});
|
});
|
||||||
|
|
||||||
const subtype_search = type.shortSignature + '$';
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
...(typelist || [...typemap.keys()]).map(t => {
|
...(typelist || [...typemap.keys()]).map(t => {
|
||||||
if (!opts.statics) return;
|
if (!opts.statics) return;
|
||||||
if (!t.startsWith(subtype_search)) return;
|
if (!subtype_search || !t.startsWith(subtype_search)) return;
|
||||||
return {
|
return {
|
||||||
label: t.slice(subtype_search.length).replace(/\$/g,'.'),
|
label: t.slice(subtype_search.length).replace(/\$/g,'.'),
|
||||||
kind: CompletionItemKind.Class,
|
kind: CompletionItemKind.Class,
|
||||||
@@ -639,8 +648,9 @@ connection.onCompletionResolve(
|
|||||||
kind: 'markdown',
|
kind: 'markdown',
|
||||||
value: `${header}\n\n${
|
value: `${header}\n\n${
|
||||||
documentation
|
documentation
|
||||||
.replace(/(^\/\*+|(?<=\n)[ \t]*\*+\/?|\*+\/)|(<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, (_,cmt,p,i,b,tt,c,lc,li,a,h) => {
|
.replace(/(^\/\*+|(?<=\n)[ \t]*\*+\/?|\*+\/)/gm, '')
|
||||||
return cmt ? ''
|
.replace(/(\n[ \t]*@[a-z]+)|(<p(?: .*)?>)|(<\/?i>|<\/?em>)|(<\/?b>|<\/?strong>|<\/?dt>)|(<\/?tt>)|(<\/?code>|<\/?pre>|<\/?blockquote>)|(\{@link.+?\}|\{@code.+?\})|(<li>)|(<a href="\{@docRoot\}.*?">.+?<\/a>)|(<h\d>)|<\/?dd ?.*?>|<\/p ?.*?>|<\/h\d ?.*?>|<\/?div ?.*?>|<\/?[uo]l ?.*?>/gim, (_,prm,p,i,b,tt,c,lc,li,a,h) => {
|
||||||
|
return prm ? ` ${prm}`
|
||||||
: p ? '\n\n'
|
: p ? '\n\n'
|
||||||
: i ? '*'
|
: i ? '*'
|
||||||
: b ? '**'
|
: b ? '**'
|
||||||
|
|||||||
Reference in New Issue
Block a user