mirror of
https://github.com/kiteco/vscode-plugin.git
synced 2024-09-11 16:08:10 +03:00
commit
511f7ca55e
@ -285,6 +285,16 @@
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.kite h3 {
|
||||
font-weight: 100;
|
||||
margin: 0;
|
||||
font-size: 1.4em;
|
||||
margin-bottom: 1em;
|
||||
margin-top: 0.5em;
|
||||
color: var(--text-color-highlight);
|
||||
}
|
||||
|
||||
.kite h4 {
|
||||
font-weight: 100;
|
||||
margin: 0;
|
||||
@ -347,19 +357,19 @@
|
||||
.kite section.summary {
|
||||
margin: 0 0 15px;
|
||||
}
|
||||
.kite section.summary.collapsible.collapse .description {
|
||||
.kite section.collapsible.collapse > div {
|
||||
max-height: 250px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.kite section.summary.collapsible.collapse .description {
|
||||
.kite section.collapsible.collapse > div {
|
||||
max-height: 250px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.kite section.summary.collapsible.collapse.overflow .description::after {
|
||||
.kite section.collapsible.collapse.overflow > div::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
height: 30px;
|
||||
|
@ -14,11 +14,6 @@ window.StickyTitle = class StickyTitle {
|
||||
return sticky;
|
||||
});
|
||||
|
||||
this.summaryLink = document.createElement('a');
|
||||
this.summaryLink.href = '#';
|
||||
this.summaryLink.dataset.action = 'expand';
|
||||
this.summaryLink.innerHTML = 'show more…';
|
||||
|
||||
scrollContainer.addEventListener('scroll', e => {
|
||||
this.scroll();
|
||||
});
|
||||
@ -29,21 +24,6 @@ window.StickyTitle = class StickyTitle {
|
||||
});
|
||||
});
|
||||
|
||||
this.summaryLink.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
const summary = this.scrollContainer.querySelector('.summary');
|
||||
if (this.summaryLink.dataset.action === 'expand') {
|
||||
this.summaryLink.dataset.action = 'collapse';
|
||||
this.summaryLink.innerHTML = 'show less…';
|
||||
summary.classList.remove('collapse');
|
||||
} else {
|
||||
this.summaryLink.dataset.action = 'expand';
|
||||
this.summaryLink.innerHTML = 'show more…';
|
||||
summary.classList.add('collapse');
|
||||
}
|
||||
this.scroll();
|
||||
});
|
||||
|
||||
this.scrollContainer.addEventListener('click', (e) => {
|
||||
this.stickies.some(sticky => {
|
||||
const bounds = sticky.getBoundingClientRect();
|
||||
@ -53,10 +33,7 @@ window.StickyTitle = class StickyTitle {
|
||||
})
|
||||
});
|
||||
|
||||
this.collapsible = true;
|
||||
const summary = this.scrollContainer.querySelector('.summary');
|
||||
summary.classList.add('collapsible');
|
||||
this.collapseSummary();
|
||||
this.handleCollapsibles();
|
||||
|
||||
window.addEventListener('resize', () => {
|
||||
this.measureWidthAndHeight();
|
||||
@ -66,26 +43,44 @@ window.StickyTitle = class StickyTitle {
|
||||
this.measureWidthAndHeight();
|
||||
}
|
||||
|
||||
collapseSummary() {
|
||||
const summary = this.scrollContainer.querySelector('.summary');
|
||||
handleCollapsibles() {
|
||||
[].slice.call(this.scrollContainer.querySelectorAll('.collapsible')).forEach(collapsible => {
|
||||
const content = collapsible.querySelector('.section-content');
|
||||
|
||||
if (this.collapsible) {
|
||||
const description = summary.querySelector('.description');
|
||||
let summaryLink = collapsible.querySelector('a[data-action="expand"]')
|
||||
if (!summaryLink) {
|
||||
summaryLink = document.createElement('a');
|
||||
summaryLink.href = '#';
|
||||
summaryLink.dataset.action = 'expand';
|
||||
summaryLink.innerHTML = 'show more…';
|
||||
|
||||
summary.classList.add('collapse');
|
||||
if (description.scrollHeight > description.offsetHeight) {
|
||||
summary.classList.add('overflow');
|
||||
summary.appendChild(this.summaryLink);
|
||||
summaryLink.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
if (summaryLink.dataset.action === 'expand') {
|
||||
summaryLink.dataset.action = 'collapse';
|
||||
summaryLink.innerHTML = 'show less…';
|
||||
collapsible.classList.remove('collapse');
|
||||
} else {
|
||||
summaryLink.dataset.action = 'expand';
|
||||
summaryLink.innerHTML = 'show more…';
|
||||
collapsible.classList.add('collapse');
|
||||
}
|
||||
this.scroll();
|
||||
});
|
||||
}
|
||||
|
||||
collapsible.classList.add('collapse');
|
||||
if (content.scrollHeight > content.offsetHeight) {
|
||||
collapsible.classList.add('overflow');
|
||||
collapsible.appendChild(summaryLink);
|
||||
} else {
|
||||
summary.classList.remove('overflow');
|
||||
if (this.summaryLink.parentNode) {
|
||||
summary.removeChild(this.summaryLink);
|
||||
collapsible.classList.remove('overflow');
|
||||
if (summaryLink.parentNode) {
|
||||
collapsible.removeChild(summaryLink);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
summary.classList.remove('collapse');
|
||||
summary.classList.remove('overflow');
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
this.scroll();
|
||||
}
|
||||
|
@ -2,6 +2,11 @@ const PYTHON_MODE = {language: 'python', scheme: 'file'};
|
||||
|
||||
const JAVASCRIPT_MODE = {language: 'javascript', scheme: 'file'};
|
||||
|
||||
const SUPPORTED_EXTENSIONS = {
|
||||
javascript: fileName => /\.js$/.test(fileName),
|
||||
python: fileName => /\.py$/.test(fileName),
|
||||
}
|
||||
|
||||
// MAX_FILE_SIZE is the maximum file size to send to Kite
|
||||
const MAX_FILE_SIZE = 2 ** 20; // 1048576
|
||||
|
||||
@ -21,13 +26,14 @@ const WARNING_COLOR = '#929497';
|
||||
const NOT_WHITELISTED = 7;
|
||||
|
||||
module.exports = {
|
||||
ATTEMPTS,
|
||||
INTERVAL,
|
||||
PYTHON_MODE,
|
||||
MAX_PAYLOAD_SIZE,
|
||||
MAX_FILE_SIZE,
|
||||
CONNECT_ERROR_LOCKOUT,
|
||||
ERROR_COLOR,
|
||||
WARNING_COLOR,
|
||||
NOT_WHITELISTED,
|
||||
ATTEMPTS,
|
||||
INTERVAL,
|
||||
PYTHON_MODE,
|
||||
MAX_PAYLOAD_SIZE,
|
||||
MAX_FILE_SIZE,
|
||||
CONNECT_ERROR_LOCKOUT,
|
||||
ERROR_COLOR,
|
||||
WARNING_COLOR,
|
||||
NOT_WHITELISTED,
|
||||
SUPPORTED_EXTENSIONS,
|
||||
};
|
@ -157,7 +157,7 @@ const wrapType = (o) => {
|
||||
: null;
|
||||
};
|
||||
|
||||
const unionType = (vs, map) =>
|
||||
const unionType = (vs, map) =>
|
||||
uniq(flatten(compact(vs.map(map))).map(wrapType)).join(' | ');
|
||||
|
||||
const returnType = (v) =>
|
||||
@ -180,15 +180,14 @@ const reportFromHover = hover => {
|
||||
const extractInstanceType = v => ({name: v.type, id: v.type_id});
|
||||
const extractFunctionType = v => {
|
||||
const detail = getFunctionDetails(v);
|
||||
detail && detail.return_value
|
||||
return detail && detail.return_value
|
||||
? detail.return_value.map(v => ({name: v.type, id: v.type_id}))
|
||||
: null;
|
||||
: [];
|
||||
};
|
||||
|
||||
const symbolType = s =>
|
||||
isFunctionKind(symbolKind(s))
|
||||
? returnType(unionType(s.value, extractFunctionType))
|
||||
: `:${unionType(s.value, extractInstanceType)}`;
|
||||
const symbolType = s => unionType(s.value, extractInstanceType);
|
||||
|
||||
const symbolReturnType = s => unionType(s.value, extractFunctionType);
|
||||
|
||||
const valueType = value =>
|
||||
isFunctionKind(value.kind)
|
||||
@ -224,4 +223,5 @@ module.exports = {
|
||||
valueType,
|
||||
idIsEmpty,
|
||||
isFunctionKind,
|
||||
symbolReturnType,
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const {StateController, Logger} = require('kite-installer');
|
||||
const {MAX_PAYLOAD_SIZE, CONNECT_ERROR_LOCKOUT} = require('./constants');
|
||||
const {MAX_FILE_SIZE, CONNECT_ERROR_LOCKOUT} = require('./constants');
|
||||
const {promisifyRequest, secondsSince} = require('./utils');
|
||||
const {normalizeDriveLetter} = require('./urls');
|
||||
|
||||
@ -25,14 +25,16 @@ module.exports = class EditorEvents {
|
||||
}
|
||||
|
||||
sendEvent(action) {
|
||||
const event = this.makeEvent(action, this.document, this.editor.selection);
|
||||
const event = this.document.getText().length > MAX_FILE_SIZE
|
||||
? {
|
||||
source: 'vscode',
|
||||
action: 'skip',
|
||||
filename: normalizeDriveLetter(this.document.fileName),
|
||||
}
|
||||
: this.makeEvent(action, this.document, this.editor.selection);
|
||||
|
||||
const payload = JSON.stringify(event);
|
||||
|
||||
if (payload.length > MAX_PAYLOAD_SIZE) {
|
||||
Logger.warn('unable to send message because length exceeded limit');
|
||||
return;
|
||||
}
|
||||
|
||||
return this.Kite.request({
|
||||
path: '/clientapi/editor/event',
|
||||
method: 'POST',
|
||||
|
@ -10,6 +10,7 @@ const {
|
||||
symbolLabel, symbolType, idIsEmpty,
|
||||
valueLabel, valueType, callSignature,
|
||||
memberLabel, parameterName, parameterDefault, parameterTypeLink,
|
||||
symbolReturnType,
|
||||
} = require('./data-utils');
|
||||
const logo = fs.readFileSync(path.resolve(__dirname, '..', 'assets', 'images', 'logo-small.svg')).toString();
|
||||
const logoLarge = fs.readFileSync(path.resolve(__dirname, '..', 'assets', 'images', 'logo-no-text.svg')).toString();
|
||||
@ -148,6 +149,7 @@ function renderExamplesList(data) {
|
||||
|
||||
return `
|
||||
<div class="examples-list">
|
||||
<h3>Examples for <code>${data.value.repr}</code></h3>
|
||||
<ul>${examples.map(m => renderExample(m)).join('')}</ul>
|
||||
</div>
|
||||
${debugData(data)}
|
||||
@ -157,6 +159,7 @@ function renderExamplesList(data) {
|
||||
function renderModule(data) {
|
||||
const {symbol} = data;
|
||||
const value = head(symbol.value);
|
||||
const kind = value.kind;
|
||||
|
||||
return `
|
||||
${renderSymbolHeader(symbol)}
|
||||
@ -166,21 +169,18 @@ function renderModule(data) {
|
||||
<div class="sections-wrapper">
|
||||
${
|
||||
value.kind === 'type'
|
||||
? `${renderParameters(value)}
|
||||
${renderPatterns(value)}
|
||||
? `
|
||||
${renderPatterns(value, 'Popular Constructor Patterns')}
|
||||
${renderParameters(value)}
|
||||
${renderLanguageSpecificArgumentsList(value)}`
|
||||
: ''
|
||||
}
|
||||
<section class="summary">
|
||||
<h4>Summary</h4>
|
||||
${symbolDescription(data)}
|
||||
</section>
|
||||
|
||||
${renderMembers(value)}
|
||||
${renderMembers(value, kind)}
|
||||
${renderDocs(data)}
|
||||
${renderUsages(data)}
|
||||
${renderExamples(data)}
|
||||
${renderLinks(data)}
|
||||
${renderDefinition(data)}
|
||||
${renderLinks(data)}
|
||||
${debugData(data)}
|
||||
</div>
|
||||
</div>
|
||||
@ -203,19 +203,15 @@ function renderFunction(data) {
|
||||
|
||||
<div class="scroll-wrapper">
|
||||
<div class="sections-wrapper">
|
||||
${renderParameters(value)}
|
||||
${renderPatterns(value)}
|
||||
${renderParameters(value)}
|
||||
${renderLanguageSpecificArgumentsList(value)}
|
||||
|
||||
<section class="summary">
|
||||
<h4>Summary</h4>
|
||||
${symbolDescription(data)}
|
||||
</section>
|
||||
|
||||
${renderReturnType(symbol)}
|
||||
${renderDocs(data)}
|
||||
${renderUsages(data)}
|
||||
${renderExamples(data)}
|
||||
${renderLinks(data)}
|
||||
${renderDefinition(data)}
|
||||
${renderLinks(data)}
|
||||
${renderInvocations(symbol)}
|
||||
${debugData(data)}
|
||||
</div>
|
||||
@ -240,14 +236,10 @@ function renderInstance(data) {
|
||||
|
||||
<div class="scroll-wrapper">
|
||||
<div class="sections-wrapper">
|
||||
<section class="summary">
|
||||
<h4>Summary</h4>
|
||||
${symbolDescription(data)}
|
||||
</section>
|
||||
|
||||
${renderDefinition(symbol)}
|
||||
${renderDocs(data)}
|
||||
${renderUsages(data)}
|
||||
${renderExamples(data)}
|
||||
${renderDefinition(symbol)}
|
||||
${renderLinks(data)}
|
||||
${debugData(data)}
|
||||
</div>
|
||||
@ -262,6 +254,16 @@ function renderInstance(data) {
|
||||
`;
|
||||
}
|
||||
|
||||
function renderDocs(data) {
|
||||
const description = symbolDescription(data);
|
||||
return description && description.trim() !== ''
|
||||
? `<section class="summary collapsible collapse">
|
||||
<h4>Docs</h4>
|
||||
<div class="section-content description">${description}</div>
|
||||
</section>`
|
||||
: '';
|
||||
}
|
||||
|
||||
function stripBody(html) {
|
||||
return (html || '').replace(/<body>/, '').replace(/<\/body>/, '');
|
||||
}
|
||||
@ -280,11 +282,11 @@ function symbolDescription(data) {
|
||||
const {symbol} = data;
|
||||
const value = head(symbol.value);
|
||||
|
||||
return `<div class="description">${data.report &&
|
||||
return data.report &&
|
||||
data.report.description_html &&
|
||||
data.report.description_html !== ''
|
||||
? stripBody(data.report.description_html)
|
||||
: (value.synopsis != '' ? value.synopsis : symbol.synopsis)}</div>`;
|
||||
: (value.synopsis != '' ? value.synopsis : symbol.synopsis);
|
||||
}
|
||||
|
||||
function renderSymbolHeader(symbol) {
|
||||
@ -359,6 +361,11 @@ function usageCommand(def) {
|
||||
return `command:kite.usage?${defData}`;
|
||||
}
|
||||
|
||||
function renderReturnType(symbol) {
|
||||
const ret = symbolReturnType(symbol);
|
||||
return ret !== '' ? section('Returns', ret) : '';
|
||||
}
|
||||
|
||||
function renderDefinition(value) {
|
||||
const def = value.report && value.report.definition;
|
||||
if (def && def.filename && def.filename.trim() !== '') {
|
||||
@ -383,6 +390,7 @@ function renderLinksList(data) {
|
||||
const links = (data.report && data.report.links) || [];
|
||||
return `
|
||||
<div class="links-list">
|
||||
<h3>Links about <code>${data.value.repr}</code></h3>
|
||||
<ul>${links.map(m => renderLink(m)).join('')}</ul>
|
||||
</div>
|
||||
${debugData(data)}
|
||||
@ -445,7 +453,7 @@ function additionalExamplesLink(examplesCount, data) {
|
||||
|
||||
function renderUsages(symbol) {
|
||||
return symbol.report && symbol.report.usages && symbol.report.usages.length
|
||||
? section('Usages from your code',
|
||||
? section('Examples from your code',
|
||||
Plan.can('usages_editor')
|
||||
? `<ul class="usages-box">
|
||||
${symbol.report.usages.map(renderUsage).join('')}
|
||||
@ -469,24 +477,26 @@ function renderUsage(usage) {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function renderMembers(value, limit) {
|
||||
function renderMembers(value, kind, limit) {
|
||||
const detail = getDetails(value, 'type', 'module')
|
||||
const {members, total_members} = detail;
|
||||
|
||||
const title = kind === 'type' ? 'Top attributes' : 'Top members'
|
||||
|
||||
return members.length === 0
|
||||
? ''
|
||||
: (limit != null
|
||||
? section('Top members', `
|
||||
? section(title, `
|
||||
<ul>
|
||||
${members.slice(0, limit).map(m => renderMember(m)).join('')}
|
||||
</ul>
|
||||
${additionalMembersLink(total_members - limit, value)}`)
|
||||
: section('Top members', `
|
||||
${additionalMembersLink(total_members - limit, value, kind)}`)
|
||||
: section(title, `
|
||||
<ul>
|
||||
${members.map(m => renderMember(m)).join('')}
|
||||
</ul>
|
||||
${total_members > members.length
|
||||
? additionalMembersLink(total_members - members.length, value)
|
||||
? additionalMembersLink(total_members - members.length, value, kind)
|
||||
: ''
|
||||
}`));
|
||||
}
|
||||
@ -495,7 +505,7 @@ function stripLeadingSlash(str) {
|
||||
return str.replace(/^\//, '');
|
||||
}
|
||||
|
||||
function renderPatterns(data) {
|
||||
function renderPatterns(data, title='Popular Patterns') {
|
||||
let patterns = '';
|
||||
const name = data.repr;
|
||||
const detail = getFunctionDetails(data);
|
||||
@ -503,7 +513,7 @@ function renderPatterns(data) {
|
||||
patterns = Plan.can('common_invocations_editor')
|
||||
? `
|
||||
<section class="patterns">
|
||||
<h4>Popular Patterns</h4>
|
||||
<h4>${title}</h4>
|
||||
<div class="section-content">${
|
||||
highlightCode(
|
||||
detail.signatures
|
||||
@ -541,7 +551,7 @@ function renderKwargs(data) {
|
||||
let kwargs = '';
|
||||
const detail = getFunctionDetails(data);
|
||||
if (detailNotEmpty(detail, 'kwarg_parameters')) {
|
||||
kwargs = `<section class="kwargs">
|
||||
kwargs = `<section class="kwargs collapsible collapse">
|
||||
<h4>**${detailGet(detail, 'kwarg').name}</h4>
|
||||
<div class="section-content"><dl>
|
||||
${
|
||||
@ -580,11 +590,11 @@ function renderMember(member) {
|
||||
|
||||
}
|
||||
|
||||
function additionalMembersLink(membersCount, value) {
|
||||
function additionalMembersLink(membersCount, value, kind) {
|
||||
return membersCount <= 0
|
||||
? ''
|
||||
: `<a href='command:kite.navigate?"members-list/${value.id}"'
|
||||
class="more-members">See ${membersCount} more members</a>`;
|
||||
class="more-members">See ${membersCount} more ${kind == 'type' ? 'attributes' : 'members'}</a>`;
|
||||
}
|
||||
|
||||
function renderParameters(value) {
|
||||
|
@ -4,7 +4,7 @@ const vscode = require('vscode');
|
||||
const os = require('os');
|
||||
const opn = require('opn');
|
||||
const {StateController, AccountManager, Logger} = require('kite-installer');
|
||||
const {PYTHON_MODE, JAVASCRIPT_MODE, ATTEMPTS, INTERVAL, ERROR_COLOR, WARNING_COLOR, NOT_WHITELISTED} = require('./constants');
|
||||
const {PYTHON_MODE, JAVASCRIPT_MODE, ATTEMPTS, INTERVAL, ERROR_COLOR, WARNING_COLOR, SUPPORTED_EXTENSIONS} = require('./constants');
|
||||
const KiteHoverProvider = require('./hover');
|
||||
const KiteCompletionProvider = require('./completion');
|
||||
const KiteSignatureProvider = require('./signature');
|
||||
@ -545,7 +545,9 @@ const Kite = {
|
||||
},
|
||||
|
||||
isDocumentGrammarSupported(d) {
|
||||
return d && this.supportedLanguages.includes(d.languageId);
|
||||
return d &&
|
||||
this.supportedLanguages.includes(d.languageId) &&
|
||||
SUPPORTED_EXTENSIONS[d.languageId](d.fileName);
|
||||
},
|
||||
|
||||
isEditorWhitelisted(e) {
|
||||
|
@ -30,7 +30,7 @@ describe('KiteHoverProvider', () => {
|
||||
expect(res.contents[0].language).to.eql('python');
|
||||
expect(res.contents[0].value).to.eql('Test.increment function');
|
||||
|
||||
expect(res.contents[1]).to.eql(`**Kite:** [web](command:kite.web?{"id":"sample:Test.increment","source":"Hover"}) [more](command:kite.more-range?{"range":[{"line":19,"character":6},{"line":19,"character":11}],"source":"Hover"}) [def](command:kite.def?{"file":"sample.py","line":50,"source":"Hover"})`);
|
||||
expect(res.contents[1].value).to.eql(`**Kite:** [web](command:kite.web?{"id":"sample:Test.increment","source":"Hover"}) [more](command:kite.more-range?{"range":[{"line":19,"character":6},{"line":19,"character":11}],"source":"Hover"}) [def](command:kite.def?{"file":"sample.py","line":50,"source":"Hover"})`);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -51,7 +51,7 @@ describe('KiteHoverProvider', () => {
|
||||
.then(res => {
|
||||
|
||||
expect(res.contents.length).to.eql(2);
|
||||
expect(res.contents[1]).to.eql(`**Kite:** [more](command:kite.more-range?{"range":[{"line":19,"character":6},{"line":19,"character":11}],"source":"Hover"})`);
|
||||
expect(res.contents[1].value).to.eql(`**Kite:** [more](command:kite.more-range?{"range":[{"line":19,"character":6},{"line":19,"character":11}],"source":"Hover"})`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user