utopia-ia/elffuss-code public
Changesets · Branches · Tags · Compare
| Changeset | d66451cc104ef57a632186b8d8768b4e29b552af895583d15ec161af002be645 |
|---|---|
| Author | KikoCis <KikoCis@users.noreply.github.com> · 2026-10-12 11:54 +02:00 |
| Committer | KikoCis <KikoCis@users.noreply.github.com> · 2026-10-12 11:54 +02:00 |
| Parents | 3040d2ec50b4, e0009187e422 |
12 files changed
added tests/ext_feedback.mjs +237 −0
| @@ -0,0 +1,237 @@ | ||
| 1 | +// Extensions: what the user SEES after installing one, and what is offered | |
| 2 | +// before. Level 1 only applies themes, grammars, snippets and language | |
| 3 | +// settings; an install that changes nothing visible felt pointless. | |
| 4 | +// | |
| 5 | +// BASE=http://localhost:8999 node tests/ext_feedback.mjs | |
| 6 | +// | |
| 7 | +// Fixtures are built in ext_fixtures.mjs and Open VSX is mocked with routes, | |
| 8 | +// so it runs offline. The LIVE part at the end installs real extensions from | |
| 9 | +// Open VSX; without network it is NOT RUN and does not count as a failure. | |
| 10 | +import { chromium } from 'playwright'; | |
| 11 | +import { pureThemeVsix, PURE_DARK, partialLangVsix, TOMLISH, jsSnippetsVsix, codeOnlyVsix } from './ext_fixtures.mjs'; | |
| 12 | + | |
| 13 | +const BASE = process.env.BASE || 'http://localhost:8999'; | |
| 14 | +const OUT = process.env.SCRATCH || '/tmp/elffuss-test'; | |
| 15 | +let fails = 0; | |
| 16 | +const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; | |
| 17 | +const notRun = (n, e) => console.log('⏭️ NOT RUN ' + n + (e ? ' — ' + e : '')); | |
| 18 | +const sleep = ms => new Promise(r => setTimeout(r, ms)); | |
| 19 | +const rgb = hex => { const h = hex.replace('#', ''); return `rgb(${parseInt(h.slice(0, 2), 16)}, ${parseInt(h.slice(2, 4), 16)}, ${parseInt(h.slice(4, 6), 16)})`; }; | |
| 20 | +async function hasta(fn, { tiempo = 12000, cada = 150 } = {}) { | |
| 21 | + const fin = Date.now() + tiempo; | |
| 22 | + let v; | |
| 23 | + while (Date.now() < fin) { try { v = await fn(); if (v) return v; } catch { /* retry */ } await sleep(cada); } | |
| 24 | + return v; | |
| 25 | +} | |
| 26 | +// internal words a user should never read in the panel | |
| 27 | +const JERGA = /contributes|customEditors|extension host|host de extensiones|main\/browser|activationEvents/i; | |
| 28 | + | |
| 29 | +const b = await chromium.launch(); | |
| 30 | + | |
| 31 | +async function nuevaPagina(locale, viewport = { width: 1280, height: 860 }) { | |
| 32 | + const ctx = await b.newContext({ locale, viewport }); | |
| 33 | + await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); | |
| 34 | + const p = await ctx.newPage(); | |
| 35 | + p.errores = []; | |
| 36 | + p.on('pageerror', e => { if (e.message !== 'Canceled') p.errores.push(e.message); }); | |
| 37 | + await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' }); | |
| 38 | + await p.evaluate(async () => { | |
| 39 | + const o = await navigator.storage.getDirectory(); | |
| 40 | + for await (const k of o.keys()) await o.removeEntry(k, { recursive: true }).catch(() => {}); | |
| 41 | + const w = async (n, t) => { const f = await o.getFileHandle(n, { create: true }); const s = await f.createWritable(); await s.write(t); await s.close(); }; | |
| 42 | + await w('app.js', '// app\nconst a = 1;\n'); | |
| 43 | + await w('data.tomlish', 'name = "x"\n# note\n'); | |
| 44 | + }); | |
| 45 | + await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); | |
| 46 | + await hasta(() => p.evaluate(() => !!window.monaco?.editor?.getEditors?.().length), { tiempo: 30000 }); | |
| 47 | + return { ctx, p }; | |
| 48 | +} | |
| 49 | +const pulsa = (p, sel) => p.click(sel, { timeout: 3000 }).catch(() => {}); | |
| 50 | +const abre = (p, path) => p.evaluate(async path => { await (await import('/js/ide.js')).openFile(path); }, path); | |
| 51 | +const fondo = p => p.evaluate(() => getComputedStyle(document.querySelector('#editor .monaco-editor-background') || document.querySelector('#editor .monaco-editor')).backgroundColor); | |
| 52 | +const abrePanel = async p => { if (!(await p.locator('#ext-panel').isVisible().catch(() => false))) { await p.click('#act-ext'); await p.waitForSelector('#ext-panel', { timeout: 10000 }); } }; | |
| 53 | +const instalaFichero = async (p, nombre, bytes) => { | |
| 54 | + await abrePanel(p); | |
| 55 | + await p.evaluate(() => { const m = document.getElementById('ext-msg'); if (m) { m.hidden = true; m.textContent = ''; } document.getElementById('ext-done')?.remove(); }); | |
| 56 | + await p.setInputFiles('#ext-file', { name: nombre, mimeType: 'application/octet-stream', buffer: Buffer.from(bytes) }); | |
| 57 | + return hasta(() => p.evaluate(() => { const m = document.getElementById('ext-msg'); return m && !m.hidden && m.textContent; }), { tiempo: 15000 }); | |
| 58 | +}; | |
| 59 | +const tarjeta = p => p.evaluate(() => document.getElementById('ext-done')?.innerText.replace(/\s+/g, ' ') || ''); | |
| 60 | +const fila = (p, id) => p.locator(`#ext-installed .ext-row[data-id="${id}"]`); | |
| 61 | + | |
| 62 | +// ── 1. Theme-only extension: applied on install, with Undo and the picker ── | |
| 63 | +{ | |
| 64 | + const { p } = await nuevaPagina('en-US'); | |
| 65 | + await abre(p, 'app.js'); | |
| 66 | + await instalaFichero(p, 'pure.vsix', pureThemeVsix()); | |
| 67 | + ok('theme: the first theme is applied on install (editor background)', await hasta(async () => (await fondo(p)) === rgb(PURE_DARK)), await fondo(p)); | |
| 68 | + const t = await tarjeta(p); | |
| 69 | + ok('theme: the notice names the theme and says it is applied', /Pure Night/.test(t) && /applied/i.test(t), t); | |
| 70 | + ok('theme: Undo and Choose theme… buttons', await p.locator('#ext-done button[data-act="undo-theme"]').count() === 1 && await p.locator('#ext-done button[data-act="pick-theme"]').count() === 1); | |
| 71 | + await pulsa(p, '#ext-done button[data-act="undo-theme"]'); | |
| 72 | + ok('theme: Undo restores the previous theme', await hasta(async () => (await fondo(p)) === 'rgb(30, 30, 30)'), await fondo(p)); | |
| 73 | + ok('theme: after Undo, an Apply now button', await hasta(() => p.locator('#ext-done button[data-act="apply-theme"]').count())); | |
| 74 | + await pulsa(p, '#ext-done button[data-act="apply-theme"]'); | |
| 75 | + ok('theme: Apply now applies it', await hasta(async () => (await fondo(p)) === rgb(PURE_DARK)), await fondo(p)); | |
| 76 | + await pulsa(p, '#ext-done button[data-act="pick-theme"]'); | |
| 77 | + ok('theme: Choose theme… opens the Color Theme picker', await hasta(() => p.locator('#ext-themepick').count())); | |
| 78 | + await p.keyboard.press('Escape'); | |
| 79 | + const now = (await fila(p, 'elffuss-test.pure-theme').locator('.ext-now').innerText().catch(() => '')).replace(/\s+/g, ' '); | |
| 80 | + ok('installed list: says which theme is active right now', /Active theme/i.test(now) && /Pure Night/.test(now), now); | |
| 81 | + await p.screenshot({ path: OUT + '/extfb-theme.png' }); | |
| 82 | + | |
| 83 | + // ── 2. Language with grammar + settings + code: open file highlighted at once ── | |
| 84 | + await abre(p, 'data.tomlish'); | |
| 85 | + ok('language: before installing, the file is plain text', (await p.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getLanguageId())) === 'plaintext'); | |
| 86 | + await instalaFichero(p, 'tomlish.vsix', partialLangVsix()); | |
| 87 | + ok('language: the open file switches to the new language', await hasta(() => p.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getLanguageId() === 'tomlish'))); | |
| 88 | + const tipos = await hasta(async () => { const x = await p.evaluate(() => window.monaco.editor.tokenize('name = 1', 'tomlish').flat().map(t => t.type)); return x.some(t => /variable\.other\.key/.test(t)) && x; }); | |
| 89 | + ok('language: the grammar tokenizes', !!tipos, JSON.stringify(tipos)); | |
| 90 | + const t2 = await tarjeta(p); | |
| 91 | + ok('language: notice says highlighting for Tomlish (.tomlish)', /Tomlish/.test(t2) && /\.tomlish/.test(t2) && /highlight/i.test(t2), t2); | |
| 92 | + ok('language: notice says the open file is already highlighted, with a button to go there', /data\.tomlish/.test(t2) && await p.locator('#ext-done button[data-act="goto"]').count() >= 1, t2); | |
| 93 | + ok('language: notice says what the settings change (comment with #, brackets)', /#/.test(t2) && /\[\s?\]/.test(t2), t2); | |
| 94 | + ok('language: notice says what does not work, in plain words, and that it comes with the next version', /format/i.test(t2) && /next version/i.test(t2) && !JERGA.test(t2), t2); | |
| 95 | + const now2 = (await fila(p, 'elffuss-test.tomlish').locator('.ext-now').innerText().catch(() => '')).replace(/\s+/g, ' '); | |
| 96 | + ok('installed list: «Highlighting 1 open file»', /Highlighting 1 open file/i.test(now2), now2); | |
| 97 | + await p.screenshot({ path: OUT + '/extfb-lang.png' }); | |
| 98 | + | |
| 99 | + // ── 3. Snippets: count, languages and prefixes to try ── | |
| 100 | + await instalaFichero(p, 'snips.vsix', jsSnippetsVsix()); | |
| 101 | + const t3 = await tarjeta(p); | |
| 102 | + ok('snippets: «4 snippets for JavaScript and TypeScript»', /4 snippets/.test(t3) && /JavaScript/.test(t3) && /TypeScript/.test(t3), t3); | |
| 103 | + ok('snippets: shows prefixes to type (clg, imp…) and how to accept', /clg/.test(t3) && /imp/.test(t3) && /Tab/.test(t3), t3); | |
| 104 | + const now3 = (await fila(p, 'elffuss-test.js-snips').locator('.ext-now').innerText().catch(() => '')).replace(/\s+/g, ' '); | |
| 105 | + ok('installed list: «4 snippets» with a link to try them', /4 snippets/.test(now3) && await fila(p, 'elffuss-test.js-snips').locator('button[data-act="try-snippet"]').count() === 1, now3); | |
| 106 | + await pulsa(p, '#ext-done button[data-act="try-snippet"]'); | |
| 107 | + ok('snippets: Try opens a JavaScript file and puts the cursor in the editor', await hasta(() => p.evaluate(() => { | |
| 108 | + const ed = window.monaco.editor.getEditors()[0]; | |
| 109 | + return document.getElementById('settings-panel').hidden && ed.getModel().getLanguageId() === 'javascript' && ed.hasTextFocus(); | |
| 110 | + }))); | |
| 111 | + | |
| 112 | + // ── 4. Code-only .vsix: not installed, said plainly ── | |
| 113 | + const m4 = await instalaFichero(p, 'previewer.vsix', codeOnlyVsix()); | |
| 114 | + ok('code-only: not installed', await fila(p, 'elffuss-test.previewer').count() === 0, m4); | |
| 115 | + ok('code-only: says its main feature needs its own code, in plain words', /own code/i.test(m4 || '') && !JERGA.test(m4 || ''), m4); | |
| 116 | + ok('code-only (custom editors): does not promise the next version', !/next version/i.test(m4 || ''), m4); | |
| 117 | + | |
| 118 | + // ── 5. Plain language everywhere in the panel ── | |
| 119 | + const todo = await p.evaluate(() => document.getElementById('ext-panel').innerText); | |
| 120 | + ok('panel text: no internal terms (contributes, customEditors, main/browser…)', !JERGA.test(todo), (todo.match(JERGA) || [''])[0]); | |
| 121 | + ok('no page errors', !p.errores.length, p.errores.slice(0, 3).join(' | ')); | |
| 122 | + await p.context().close(); | |
| 123 | +} | |
| 124 | + | |
| 125 | +// ── 6. Search results (Open VSX mocked): verdict before installing ── | |
| 126 | +{ | |
| 127 | + const { ctx, p } = await nuevaPagina('en-US'); | |
| 128 | + const manifests = { | |
| 129 | + 'elffuss-test/previewer': { publisher: 'elffuss-test', name: 'previewer', version: '1.0.0', displayName: 'Rich Previewer', description: 'LaTeX, STL and video preview with right-click copy', categories: ['Visualization', 'Other'], main: './dist/extension.js', | |
| 130 | + contributes: { languages: [{ id: 'csv', aliases: ['CSV'], extensions: ['.csv'] }, { id: 'tsv', extensions: ['.tsv'] }], commands: [{}], menus: {}, customEditors: [{}], configuration: {} } }, | |
| 131 | + 'elffuss-test/tomlish': { publisher: 'elffuss-test', name: 'tomlish', version: '1.0.0', displayName: 'Tomlish Support', categories: ['Programming Languages', 'Formatters'], main: './x.js', browser: './b.js', | |
| 132 | + contributes: { languages: [{ id: 'tomlish', aliases: ['Tomlish'], extensions: ['.tomlish'], configuration: './c.json' }], grammars: [{ language: 'tomlish', scopeName: 'source.tomlish', path: './g.json' }], commands: [{}] } }, | |
| 133 | + 'elffuss-test/heavy': { publisher: 'elffuss-test', name: 'heavy', version: '1.0.0', displayName: 'Heavy Workshop', categories: ['Programming Languages', 'Linters'], main: './x.js', | |
| 134 | + contributes: { languages: [{ id: 'heavy', aliases: ['Heavy'], extensions: ['.hv'], configuration: './c.json' }], grammars: [{ language: 'heavy', scopeName: 'source.hv', path: './g.json' }], commands: new Array(12).fill({}), views: { x: [{ type: 'webview' }] }, customEditors: [{}] } }, | |
| 135 | + 'elffuss-test/pure-theme': { publisher: 'elffuss-test', name: 'pure-theme', version: '1.0.0', displayName: 'Pure Theme', categories: ['Themes'], contributes: { themes: [{ label: 'Pure Night', path: './n.json' }, { label: 'Pure Dusk', path: './d.json' }] } }, | |
| 136 | + }; | |
| 137 | + const descargas = []; | |
| 138 | + await ctx.route('https://open-vsx.org/**', route => { | |
| 139 | + const u = new URL(route.request().url()); | |
| 140 | + const json = o => route.fulfill({ status: 200, contentType: 'application/json', headers: { 'access-control-allow-origin': '*' }, body: JSON.stringify(o) }); | |
| 141 | + if (u.pathname === '/api/-/search') { | |
| 142 | + return json({ totalSize: 4, offset: 0, extensions: Object.values(manifests).map(m => ({ namespace: m.publisher, name: m.name, version: m.version, displayName: m.displayName, description: m.description || '', downloadCount: 10 })) }); | |
| 143 | + } | |
| 144 | + const mm = /^\/api\/([^/]+)\/([^/]+)\/([^/]+)\/file\/package\.json$/.exec(u.pathname); | |
| 145 | + if (mm) return json(manifests[`${mm[1]}/${mm[2]}`]); | |
| 146 | + const md = /^\/api\/([^/]+)\/([^/]+)(?:\/([^/]+))?$/.exec(u.pathname); | |
| 147 | + if (md && manifests[`${md[1]}/${md[2]}`]) { | |
| 148 | + const m = manifests[`${md[1]}/${md[2]}`]; | |
| 149 | + return json({ namespace: m.publisher, name: m.name, version: m.version, displayName: m.displayName, license: 'MIT', files: { manifest: `https://open-vsx.org/api/${m.publisher}/${m.name}/${m.version}/file/package.json`, download: `https://open-vsx.org/api/${m.publisher}/${m.name}/${m.version}/file/x.vsix` } }); | |
| 150 | + } | |
| 151 | + descargas.push(u.pathname); | |
| 152 | + return route.fulfill({ status: 404, body: '' }); | |
| 153 | + }); | |
| 154 | + await abrePanel(p); | |
| 155 | + await p.fill('#ext-q', 'anything'); | |
| 156 | + await p.press('#ext-q', 'Enter'); | |
| 157 | + const r = id => p.locator(`#ext-results .ext-row[data-id="${id}"]`); | |
| 158 | + await r('elffuss-test.pure-theme').waitFor({ timeout: 10000 }).catch(() => {}); | |
| 159 | + const listo = await hasta(() => p.evaluate(() => document.querySelectorAll('#ext-results .ext-verdict').length >= 4)); | |
| 160 | + ok('results: every row gets a verdict before installing', !!listo); | |
| 161 | + const v = async id => (await r(id).locator('.ext-verdict').innerText().catch(() => '')).replace(/\s+/g, ' '); | |
| 162 | + const btn = id => r(id).locator('.ext-install'); | |
| 163 | + const vPrev = await v('elffuss-test.previewer'); | |
| 164 | + ok('code-only: «The main thing … does not work in Code: it needs to run its own code»', /main/i.test(vPrev) && /does not work in Code/i.test(vPrev) && /own code/i.test(vPrev), vPrev); | |
| 165 | + ok('code-only: Install is disabled and labelled so', (await btn('elffuss-test.previewer').getAttribute('aria-disabled')) === 'true' && !/^Install$/.test((await btn('elffuss-test.previewer').innerText()).trim()), await btn('elffuss-test.previewer').innerText()); | |
| 166 | + ok('code-only with custom editors: no «next version» promise', !/next version/i.test(vPrev), vPrev); | |
| 167 | + await btn('elffuss-test.previewer').click({ timeout: 3000 }).catch(() => {}); | |
| 168 | + await sleep(400); | |
| 169 | + ok('code-only: clicking it downloads nothing', !descargas.some(x => /previewer/.test(x)), descargas.join(' ')); | |
| 170 | + const vToml = await v('elffuss-test.tomlish'); | |
| 171 | + ok('partial: «Partly works» naming the language, and the missing part in plain words', /Tomlish/.test(vToml) && /format/i.test(vToml) && /next version/i.test(vToml) && !JERGA.test(vToml), vToml); | |
| 172 | + ok('partial: the button says what you get («Install only the highlighting»)', /only the highlighting/i.test(await btn('elffuss-test.tomlish').innerText()), await btn('elffuss-test.tomlish').innerText()); | |
| 173 | + const vHeavy = await v('elffuss-test.heavy'); | |
| 174 | + ok('mostly code: leads with the main feature not working, then «Only … would apply: highlighting for Heavy»', /does not work in Code/i.test(vHeavy) && /Only/.test(vHeavy) && /Heavy/.test(vHeavy), vHeavy); | |
| 175 | + ok('mostly code: install is a secondary button', /ghost/.test(await btn('elffuss-test.heavy').getAttribute('class')) && /only/i.test(await btn('elffuss-test.heavy').innerText())); | |
| 176 | + const vPure = await v('elffuss-test.pure-theme'); | |
| 177 | + ok('declarative: plain Install and the theme names', (await btn('elffuss-test.pure-theme').innerText()).trim() === 'Install' && /Pure Night/.test(vPure), vPure); | |
| 178 | + await r('elffuss-test.previewer').locator('.ext-name').click({ timeout: 3000 }).catch(() => {}); | |
| 179 | + const det = await hasta(async () => { const x = await r('elffuss-test.previewer').locator('.ext-detail').innerText({ timeout: 2000 }); return !/Reading/.test(x) && x; }); | |
| 180 | + ok('details: plain language, no raw contribution names', !!det && !JERGA.test(det) && !/commands|menus|configuration/.test(det), det); | |
| 181 | + const todo = await p.evaluate(() => document.getElementById('ext-panel').innerText); | |
| 182 | + ok('results panel: no internal terms', !JERGA.test(todo), (todo.match(JERGA) || [''])[0]); | |
| 183 | + await p.screenshot({ path: OUT + '/extfb-results.png' }); | |
| 184 | + // keyboard: the disabled button still takes focus and is announced as such | |
| 185 | + await btn('elffuss-test.previewer').focus({ timeout: 3000 }).catch(() => {}); | |
| 186 | + const nombre = await btn('elffuss-test.previewer').evaluate(b => (b.getAttribute('aria-label') || b.textContent) + ' | ' + (b.getAttribute('aria-describedby') ? document.getElementById(b.getAttribute('aria-describedby'))?.textContent : '')); | |
| 187 | + ok('a11y: the disabled button is focusable and its reason is linked (aria-describedby)', /does not work/i.test(nombre), nombre); | |
| 188 | + await ctx.close(); | |
| 189 | +} | |
| 190 | + | |
| 191 | +// ── 7. Spanish + phone width ── | |
| 192 | +{ | |
| 193 | + const { p } = await nuevaPagina('es-ES'); | |
| 194 | + await abrePanel(p); // the activity bar is in the drawer on a phone | |
| 195 | + await p.setViewportSize({ width: 390, height: 800 }); | |
| 196 | + await instalaFichero(p, 'pure.vsix', pureThemeVsix()); | |
| 197 | + const t = await tarjeta(p); | |
| 198 | + ok('es: «Tema «Pure Night» aplicado»', /Tema «Pure Night» aplicado/.test(t), t); | |
| 199 | + ok('es: botones Deshacer y Elegir tema…', /Deshacer/.test(t) && /Elegir tema/.test(t), t); | |
| 200 | + const ancho = await p.evaluate(() => { const x = document.getElementById('ext-panel'); return [x.scrollWidth, x.clientWidth, document.documentElement.scrollWidth, innerWidth]; }); | |
| 201 | + ok('phone width: no horizontal overflow', ancho[0] <= ancho[1] + 1 && ancho[2] <= ancho[3] + 1, ancho.join(',')); | |
| 202 | + const fuera = await p.evaluate(() => [...document.querySelectorAll('#ext-done button')].filter(b => { const r = b.getBoundingClientRect(); return r.right > innerWidth + 1 || r.left < -1; }).length); | |
| 203 | + ok('phone width: notice buttons fit on screen', fuera === 0, String(fuera)); | |
| 204 | + await p.screenshot({ path: OUT + '/extfb-phone-es.png' }); | |
| 205 | + const todo = await p.evaluate(() => document.getElementById('ext-panel').innerText); | |
| 206 | + ok('es: sin términos internos', !JERGA.test(todo), (todo.match(JERGA) || [''])[0]); | |
| 207 | + await p.context().close(); | |
| 208 | +} | |
| 209 | + | |
| 210 | +// ── LIVE: real Open VSX ── | |
| 211 | +{ | |
| 212 | + const vivo = await fetch('https://open-vsx.org/api/esbenp/prettier-vscode', { signal: AbortSignal.timeout(8000) }).then(r => r.ok).catch(() => false); | |
| 213 | + if (!vivo) notRun('live Open VSX', 'no network'); | |
| 214 | + else { | |
| 215 | + const { p } = await nuevaPagina('en-US'); | |
| 216 | + await abrePanel(p); | |
| 217 | + await p.fill('#ext-q', 'prettier'); | |
| 218 | + await p.press('#ext-q', 'Enter'); | |
| 219 | + const row = p.locator('#ext-results .ext-row[data-id="esbenp.prettier-vscode"]'); | |
| 220 | + await row.waitFor({ timeout: 20000 }).catch(() => {}); | |
| 221 | + const dis = await hasta(async () => (await row.locator('.ext-install').getAttribute('aria-disabled')) === 'true', { tiempo: 20000 }); | |
| 222 | + ok('live: Prettier is not offered as a plain Install', !!dis, await row.innerText().catch(() => '')); | |
| 223 | + await p.fill('#ext-q', 'dracula'); | |
| 224 | + await p.press('#ext-q', 'Enter'); | |
| 225 | + const d = p.locator('#ext-results .ext-row[data-id="dracula-theme.theme-dracula"]'); | |
| 226 | + await d.waitFor({ timeout: 20000 }).catch(() => {}); | |
| 227 | + await d.locator('.ext-install').click().catch(() => {}); | |
| 228 | + ok('live: Dracula applied on install', await hasta(async () => (await fondo(p)) === 'rgb(40, 42, 54)', { tiempo: 40000 }), await fondo(p)); | |
| 229 | + await p.screenshot({ path: OUT + '/extfb-live-dracula.png' }); | |
| 230 | + ok('live: no page errors', !p.errores.length, p.errores.slice(0, 3).join(' | ')); | |
| 231 | + await p.context().close(); | |
| 232 | + } | |
| 233 | +} | |
| 234 | + | |
| 235 | +console.log(fails ? `\n❌ ${fails} FAILURE(S)` : '\n✅ EXTENSIONS: VISIBLE EFFECT AFTER INSTALL OK'); | |
| 236 | +await b.close(); | |
| 237 | +process.exit(fails ? 1 : 0); |
modified tests/ext_fixtures.mjs +52 −0
| @@ -299,3 +299,55 @@ | ||
| 299 | 299 | }, |
| 300 | 300 | }, [['extension/conf.json', JSON.stringify({ wordPattern: '(a+)+$', brackets: [['(', ')']] })]]); |
| 301 | 301 | } |
| 302 | + | |
| 303 | +// ── lo que se ve al instalar (ext_feedback.mjs) ────────────────────────────── | |
| 304 | +// Solo código: vistas previas propias, comandos, menús y dos lenguajes SIN | |
| 305 | +// gramática ni configuración (como una extensión real de vista previa). Aquí no | |
| 306 | +// aporta nada visible: no se ofrece instalarla. | |
| 307 | +export function codeOnlyVsix() { | |
| 308 | + return paquete({ | |
| 309 | + name: 'previewer', displayName: 'Rich Previewer', description: 'LaTeX, STL and video preview with right-click copy', | |
| 310 | + categories: ['Visualization', 'Other'], main: './dist/extension.js', | |
| 311 | + contributes: { | |
| 312 | + languages: [{ id: 'csv', aliases: ['CSV'], extensions: ['.csv'] }, { id: 'tsv', aliases: ['TSV'], extensions: ['.tsv'] }], | |
| 313 | + commands: [{ command: 'pv.copy', title: 'Copy' }], menus: { 'editor/context': [] }, | |
| 314 | + customEditors: [{ viewType: 'pv.stl', displayName: 'STL', selector: [{ filenamePattern: '*.stl' }] }], | |
| 315 | + configuration: { properties: {} }, | |
| 316 | + }, | |
| 317 | + }, [['extension/dist/extension.js', 'throw new Error("must never run")', { method: 99 }]]); | |
| 318 | +} | |
| 319 | +// Resaltado + configuración de un lenguaje nuevo, y además código para el | |
| 320 | +// navegador (formatear, comandos): funciona en parte. | |
| 321 | +export const TOMLISH = { lang: 'tomlish', ext: '.tomlish', scope: 'source.tomlish', key: '#E06C75' }; | |
| 322 | +export function partialLangVsix() { | |
| 323 | + const g = { scopeName: TOMLISH.scope, patterns: [{ match: '^\\s*[a-z]+(?=\\s*=)', name: 'variable.other.key.tomlish' }, { match: '#.*$', name: 'comment.line.tomlish' }] }; | |
| 324 | + return paquete({ | |
| 325 | + name: 'tomlish', displayName: 'Tomlish Support', description: 'Fully-featured Tomlish support', | |
| 326 | + categories: ['Programming Languages', 'Formatters'], main: './dist/extension.js', browser: './dist/browser.js', | |
| 327 | + contributes: { | |
| 328 | + languages: [{ id: TOMLISH.lang, aliases: ['Tomlish'], extensions: [TOMLISH.ext], configuration: './conf.json' }], | |
| 329 | + grammars: [{ language: TOMLISH.lang, scopeName: TOMLISH.scope, path: './g.json' }], | |
| 330 | + commands: [{ command: 't.fmt', title: 'Format' }], configuration: { properties: {} }, | |
| 331 | + }, | |
| 332 | + }, [['extension/g.json', JSON.stringify(g)], ['extension/conf.json', JSON.stringify({ comments: { lineComment: '#' }, brackets: [['[', ']'], ['{', '}']], autoClosingPairs: [{ open: '[', close: ']' }, { open: '"', close: '"' }] })], | |
| 333 | + ['extension/dist/extension.js', 'throw new Error("must never run")', { method: 99 }]]); | |
| 334 | +} | |
| 335 | +// Solo temas, sin código. | |
| 336 | +export const PURE_DARK = '#2A1B3D'; | |
| 337 | +export function pureThemeVsix() { | |
| 338 | + const t = bg => JSON.stringify({ colors: { 'editor.background': bg, 'editor.foreground': '#F8F8F2' }, tokenColors: [{ scope: 'keyword', settings: { foreground: '#FF79C6' } }] }); | |
| 339 | + return paquete({ name: 'pure-theme', displayName: 'Pure Theme', categories: ['Themes'], contributes: { themes: [ | |
| 340 | + { label: 'Pure Night', uiTheme: 'vs-dark', path: './night.json' }, { label: 'Pure Dusk', uiTheme: 'vs-dark', path: './dusk.json' }, | |
| 341 | + ] } }, [['extension/night.json', t(PURE_DARK)], ['extension/dusk.json', t('#3A2B4D')]]); | |
| 342 | +} | |
| 343 | +// Snippets para JavaScript, sin código. | |
| 344 | +export function jsSnippetsVsix() { | |
| 345 | + const s = { | |
| 346 | + 'Console log': { prefix: 'clg', body: 'console.log($1);' }, | |
| 347 | + 'Import': { prefix: 'imp', body: "import $1 from '$2';" }, | |
| 348 | + 'Arrow': { prefix: 'fn', body: 'const $1 = ($2) => {$0};' }, | |
| 349 | + 'Group': { Inner: { prefix: 'thr', body: 'throw new Error($1);' } }, | |
| 350 | + }; | |
| 351 | + return paquete({ name: 'js-snips', displayName: 'JS Snips', categories: ['Snippets'], contributes: { snippets: [{ language: 'javascript', path: './s.json' }, { language: 'typescript', path: './s.json' }] } }, | |
| 352 | + [['extension/s.json', JSON.stringify(s)]]); | |
| 353 | +} |
modified tests/ext_unit.mjs +27 −0
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | import { sanitizeGrammar } from '../web/js/ext/grammars.js'; |
| 14 | 14 | import { textoError, textoAviso } from '../web/js/ext/panel.js'; |
| 15 | 15 | import { STRINGS } from '../web/js/ext/i18n.js'; |
| 16 | +import { describe as veredicto } from '../web/js/ext/verdict.js'; | |
| 16 | 17 | import tm from '../web/js/ext/vendor/vscode-textmate@9.3.2/main.js'; |
| 17 | 18 | import { zip, themeVsix, elfscriptVsix, THEME_DARK, ELFS, EVIL_GRAMMAR, brokenThemeVsix, noPublisherVsix, slowRegexVsix, SLOW } from './ext_fixtures.mjs'; |
| 18 | 19 | |
| @@ -290,5 +291,31 @@ | ||
| 290 | 291 | ok('textos del panel: ES y EN con las mismas claves', !faltan('es').length, faltan('es').join(' ')); |
| 291 | 292 | } |
| 292 | 293 | |
| 294 | +// ── veredicto en llano (verdict.js) y textos sin jerga ── | |
| 295 | +{ | |
| 296 | + const JERGA = /contributes|customEditors|extension host|host de extensiones|main\/browser|activationEvents|\bMonaco\b/i; | |
| 297 | + const malos = Object.entries(STRINGS).flatMap(([l, t]) => Object.entries(t).filter(([, v]) => JERGA.test(v)).map(([k]) => `${l}.${k}`)); | |
| 298 | + ok('textos del panel: ningún término interno (contributes, customEditors, main/browser, host…)', !malos.length, malos.join(' ')); | |
| 299 | + // como la extensión real de vista previa: código + editores propios + 2 lenguajes sin colores | |
| 300 | + const prev = veredicto({ hasCode: true, browserEntry: false, categories: ['Visualization', 'Other'], sizes: { languages: 2, commands: 9, customEditors: 8, menus: 3, configuration: 2 }, | |
| 301 | + ignored: [{ key: 'commands' }, { key: 'customEditors' }, { key: 'menus' }, { key: 'configuration' }], themes: [], highlight: [], settingsOnly: [], snippets: [] }); | |
| 302 | + ok('veredicto: solo código → no se ofrece instalar, y sin prometer «la siguiente versión» (editores propios)', prev.kind === 'code' && prev.button.disabled && prev.future === 'never' && !/next version/i.test(prev.verdict + prev.lines.join(' ')), JSON.stringify(prev)); | |
| 303 | + ok('veredicto: dice lo principal en llano («its own previews»)', /its own previews/.test(prev.verdict) && !JERGA.test(prev.verdict + prev.lines.join(' ')), prev.verdict); | |
| 304 | + const fmt = veredicto({ hasCode: true, browserEntry: true, categories: ['Formatters'], sizes: { commands: 2, configuration: 3 }, ignored: [{ key: 'commands' }, { key: 'configuration' }, { key: 'jsonValidation' }], themes: [], highlight: [], settingsOnly: [], snippets: [] }); | |
| 305 | + ok('veredicto: formateador con código para el navegador → «llegará con la siguiente versión»', fmt.kind === 'code' && fmt.future === 'next' && /formatting code/.test(fmt.verdict) && /next version/.test(fmt.lines.join(' ')), JSON.stringify(fmt)); | |
| 306 | + const toml = veredicto({ hasCode: true, browserEntry: true, categories: ['Programming Languages', 'Linters', 'Formatters'], sizes: { grammars: 3, languages: 1, commands: 5, menus: 1, configuration: 2 }, | |
| 307 | + ignored: [{ key: 'commands' }, { key: 'menus' }, { key: 'configuration' }, { key: 'semanticTokenTypes' }], themes: [], highlight: [{ id: 'toml', name: 'TOML', exts: ['.toml'] }], settingsOnly: [], snippets: [] }); | |
| 308 | + ok('veredicto: lenguaje + código → funciona en parte, nombra TOML, botón «solo el resaltado»', toml.kind === 'partial' && /TOML/.test(toml.verdict) && toml.button.key === 'installOnlyHighlight' && !toml.button.disabled, JSON.stringify(toml)); | |
| 309 | + const tema = veredicto({ hasCode: false, categories: ['Themes'], sizes: { themes: 2 }, ignored: [], themes: ['Dracula', 'Dracula Soft'], highlight: [], settingsOnly: [], snippets: [] }); | |
| 310 | + ok('veredicto: solo temas → «Works in Code» con los nombres y botón Instalar', tema.kind === 'full' && /Dracula/.test(tema.verdict) && tema.button.key === 'install', JSON.stringify(tema)); | |
| 311 | + const taller = veredicto({ hasCode: true, browserEntry: false, categories: ['Programming Languages', 'Snippets', 'Linters'], sizes: { commands: 46, views: 1, customEditors: 1, grammars: 16 }, webviews: true, | |
| 312 | + ignored: [{ key: 'commands' }, { key: 'views' }, { key: 'customEditors' }], themes: [], highlight: [{ id: 'latex', name: 'LaTeX', exts: ['.tex'] }], settingsOnly: [], snippets: [{ id: 'latex', name: 'LaTeX', count: null }] }); | |
| 313 | + ok('veredicto: sobre todo código → primero lo que no funciona, luego «Only … would apply», botón secundario', taller.kind === 'mostlyCode' && /does not work in Code/.test(taller.verdict) && /^Only/.test(taller.lines[0]) && /LaTeX/.test(taller.lines[0]) && taller.button.style === 'ghost', JSON.stringify(taller)); | |
| 314 | + const sinTraducir = veredicto({ hasCode: false, categories: ['Themes'], sizes: { themes: 1 }, ignored: [], themes: ['%themeLabel%'], highlight: [], settingsOnly: [], snippets: [] }); | |
| 315 | + ok('veredicto: un nombre sin traducir (%clave%) no se enseña: se cuenta', !/%/.test(sinTraducir.verdict) && /a colour theme/.test(sinTraducir.verdict), sinTraducir.verdict); | |
| 316 | + const nombres = veredicto({ hasCode: true, categories: ['Other'], sizes: { foo: 1 }, ignored: [{ key: 'someNewThing' }], themes: [], highlight: [], settingsOnly: [], snippets: [] }); | |
| 317 | + ok('veredicto: una contribución desconocida sale como «other features», no con su nombre', !/someNewThing/.test(nombres.verdict + nombres.lines.join(' ')), nombres.verdict); | |
| 318 | +} | |
| 319 | + | |
| 293 | 320 | console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ EXTENSIONES (Node): vsix, formatos, temas, lenguajes y snippets OK'); |
| 294 | 321 | process.exit(fails ? 1 : 0); |
modified tests/extensions.mjs +9 −8
| @@ -87,7 +87,7 @@ | ||
| 87 | 87 | await instalaFichero('elf-theme.vsix', themeVsix()); |
| 88 | 88 | ok('tema instalado desde .vsix', await hasta(async () => (await filaInstalada('elffuss-test.elf-theme').count()) === 1), await p.locator('#ext-msg').textContent()); |
| 89 | 89 | const textoFila = await filaInstalada('elffuss-test.elf-theme').innerText(); |
| 90 | -ok('la fila dice qué aplica y qué no (commands necesita código, main no se ejecuta)', /2 (temas|themes)/.test(textoFila) && /commands/.test(textoFila) && /(main\/browser)/.test(textoFila), textoFila.replace(/\s+/g, ' ').slice(0, 220)); | |
| 90 | +ok('la fila dice en llano qué hace ahora y qué no funciona (sus acciones necesitan su código)', /Active theme: “Elf Dark”/.test(textoFila) && /Does not work: .*its own actions/.test(textoFila) && !/commands|main\/browser|extension host/.test(textoFila), textoFila.replace(/\s+/g, ' ').slice(0, 320)); | |
| 91 | 91 | const chipOscuro = filaInstalada('elffuss-test.elf-theme').locator('.ext-theme-chips .ext-chip').first(); |
| 92 | 92 | await chipOscuro.click(); |
| 93 | 93 | ok('tema aplicado: fondo del editor', await hasta(async () => (await fondo()) === rgb(THEME_DARK.bg)), await fondo()); |
| @@ -321,10 +321,10 @@ | ||
| 321 | 321 | |
| 322 | 322 | // J3. lo que no se pudo leer se dice, en la fila y al instalar |
| 323 | 323 | const msgMedio = await instalaFichero('half.vsix', brokenThemeVsix()); |
| 324 | -ok('instalada, y el mensaje avisa de lo que no se pudo usar', msgMedio === '“Half Broken” installed. 1 part could not be used.', msgMedio); | |
| 324 | +ok('instalada, y el mensaje avisa de lo que no se pudo usar', msgMedio === '“Half Broken” installed. Theme “Good One” applied. 1 part could not be used.', msgMedio); | |
| 325 | 325 | ok('…anunciado (role=status)', (await p.getAttribute('#ext-msg', 'role')) === 'status'); |
| 326 | 326 | const filaMedio = filaInstalada('elffuss-test.half-broken'); |
| 327 | -ok('la fila: «Applies: 1 theme» y el aviso plegado', /Applies: 1 theme\b/.test(await filaMedio.innerText()) && (await filaMedio.locator('details.ext-warn summary').innerText()) === '1 part could not be used', (await filaMedio.innerText()).replace(/\s+/g, ' ')); | |
| 327 | +ok('la fila: «Active theme: “Good One”» y el aviso plegado', /Active theme: “Good One”/.test(await filaMedio.innerText()) && (await filaMedio.locator('details.ext-warn summary').innerText()) === '1 part could not be used', (await filaMedio.innerText()).replace(/\s+/g, ' ')); | |
| 328 | 328 | await filaMedio.locator('details.ext-warn summary').focus(); |
| 329 | 329 | await p.keyboard.press('Enter'); |
| 330 | 330 | const desplegado = await filaMedio.locator('details.ext-warn').evaluate(d => ({ open: d.open, li: d.querySelector('li')?.getClientRects().length > 0, texto: d.querySelector('li')?.textContent })); |
| @@ -335,7 +335,7 @@ | ||
| 335 | 335 | // J4. lo que no se aplica no se cuenta como aplicado |
| 336 | 336 | await instalaFichero('json.vsix', jsonGrammarVsix()); |
| 337 | 337 | const textoJson = (await filaInstalada('elffuss-test.json-x').innerText()).replace(/\s+/g, ' '); |
| 338 | -ok('gramática y configuración de JSON: «nada aplicable» y las dos en «Not applied»', textoJson.includes('Nothing in this extension can be applied here.') && textoJson.includes('Not applied: json grammar (Monaco keeps its built-in highlighting) · json settings (Monaco keeps its own)') && !/\b1 (grammar|language)\b/.test(textoJson), textoJson); | |
| 338 | +ok('gramática y configuración de JSON: «nada aplicable» y que Code mantiene su resaltado de JSON', textoJson.includes('Nothing in this extension can be applied here.') && textoJson.includes('Code already highlights JSON its own way and keeps it.') && !/Monaco|\b1 (grammar|language)\b/.test(textoJson), textoJson); | |
| 339 | 339 | |
| 340 | 340 | // J5. el foco no se pierde al repintar la lista de instaladas |
| 341 | 341 | await filaMedio.locator('.ext-theme-chips .ext-chip').first().focus(); |
| @@ -368,14 +368,15 @@ | ||
| 368 | 368 | await p.press('#ext-q', 'Enter'); |
| 369 | 369 | const filaFalsa = p.locator('#ext-results .ext-row[data-id="elffuss-test.fake"]'); |
| 370 | 370 | ok('búsqueda: el resultado llega y se anuncia («1 result»)', await hasta(async () => (await filaFalsa.count()) === 1 && (await p.textContent('#ext-status')) === '1 result'), await p.textContent('#ext-status')); |
| 371 | -ok('Install con nombre propio para el lector («Install Fake JSON»)', (await filaFalsa.locator('.ext-install').getAttribute('aria-label')) === 'Install Fake JSON'); | |
| 371 | +ok('el botón dice que no hay nada que aplicar, con nombre propio para el lector', await hasta(async () => (await filaFalsa.locator('.ext-install').getAttribute('aria-label')) === 'Nothing to apply: Fake JSON'), await filaFalsa.locator('.ext-install').getAttribute('aria-label')); | |
| 372 | 372 | await filaFalsa.locator('.ext-install').focus(); |
| 373 | 373 | await p.keyboard.press('Shift+Tab'); |
| 374 | 374 | const nombreBtn = await activo(); |
| 375 | 375 | ok('Shift+Tab desde Install: el nombre, que es un botón de detalle plegado', nombreBtn.cls === 'ext-name' && (await p.evaluate(() => document.activeElement.getAttribute('aria-expanded'))) === 'false', JSON.stringify(nombreBtn)); |
| 376 | 376 | await p.keyboard.press('Enter'); |
| 377 | -const detalleAbierto = await hasta(() => p.evaluate(() => { const b = document.activeElement, d = document.getElementById(b.getAttribute('aria-controls')); return b.getAttribute('aria-expanded') === 'true' && d && !d.hidden && /Nothing in this extension/.test(d.textContent) && d.textContent; })); | |
| 378 | -ok('Enter: el detalle se despliega (aria-expanded) y dice qué aplicaría, también lo de JSON', !!detalleAbierto && /Not applied: json grammar/.test(detalleAbierto), String(detalleAbierto)); | |
| 377 | +const detalleAbierto = await hasta(() => p.evaluate(() => { const b = document.activeElement, d = document.getElementById(b.getAttribute('aria-controls')); return b.getAttribute('aria-expanded') === 'true' && d && !d.hidden && /Licence/.test(d.textContent) && d.textContent; })); | |
| 378 | +const veredictoFalsa = await filaFalsa.locator('.ext-verdict').innerText().catch(() => ''); | |
| 379 | +ok('Enter: el detalle se despliega (aria-expanded) y la fila dice qué aplicaría, también lo de JSON', !!detalleAbierto && /Nothing in this extension/.test(veredictoFalsa) && /Code already highlights JSON/.test(veredictoFalsa), String(detalleAbierto) + ' | ' + veredictoFalsa); | |
| 379 | 380 | // (isDisabled() de Playwright cuenta aria-disabled como deshabilitado: aquí se |
| 380 | 381 | // mira la propiedad del DOM, que es la que le quitaría el foco) |
| 381 | 382 | const inst = await filaFalsa.locator('.ext-install').evaluate(b => { b.focus(); return { aria: b.getAttribute('aria-disabled'), disabled: b.disabled, foco: document.activeElement === b }; }); |
| @@ -492,7 +493,7 @@ | ||
| 492 | 493 | const fila = p.locator('#ext-results .ext-row[data-id="vscode.theme-monokai"]'); |
| 493 | 494 | ok('Open VSX: búsqueda con resultados', await hasta(async () => (await fila.count()) === 1, { tiempo: 20000 })); |
| 494 | 495 | await fila.locator('.ext-main').click(); |
| 495 | - ok('Open VSX: el detalle dice qué aplicaría (sin bajar el .vsix)', await hasta(async () => /1 (tema|theme)/.test(await fila.locator('.ext-detail').innerText()), { tiempo: 20000 }), await fila.locator('.ext-detail').innerText()); | |
| 496 | + ok('Open VSX: la fila dice qué aplicaría (sin bajar el .vsix), sin claves %sin traducir%', await hasta(async () => (t => /^Works in Code: adds a colour theme\.$/.test(t) && !/%\w+%/.test(t))(await fila.locator('.ext-verdict').innerText()), { tiempo: 20000 }), await fila.locator('.ext-verdict').innerText().catch(() => '')); | |
| 496 | 497 | await fila.locator('.ext-install').click(); |
| 497 | 498 | ok('Open VSX: vscode.theme-monokai instalada (SHA-256 comprobada)', await hasta(async () => (await filaInstalada('vscode.theme-monokai').count()) === 1, { tiempo: 30000 }) && /SHA-256/.test(await filaInstalada('vscode.theme-monokai').innerText())); |
| 498 | 499 | await filaInstalada('vscode.theme-monokai').locator('.ext-theme-chips .ext-chip').first().click(); |
modified web/css/ext.css +22 −5
| @@ -20,7 +20,7 @@ | ||
| 20 | 20 | /* vacío sigue en la página (región viva), pero sin ocupar sitio */ |
| 21 | 21 | .ext-msg:empty { margin: 0; padding: 0; border: 0; } |
| 22 | 22 | /* solo para lectores de pantalla */ |
| 23 | -.ext-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; } | |
| 23 | +.ext-msg.ext-msg-sr, .ext-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; } | |
| 24 | 24 | .ext-hint { font-size: .78rem; margin: 10px 0 2px; } |
| 25 | 25 | .ext-results, .ext-installed { margin-top: 4px; } |
| 26 | 26 | .ext-row { display: flex; align-items: flex-start; gap: 10px; padding: 9px 10px; background: var(--bg3); border: 1px solid var(--line); border-radius: 9px; margin-bottom: 6px; font-size: .8rem; } |
| @@ -42,8 +42,24 @@ | ||
| 42 | 42 | .ext-meta a { color: var(--accent2); } |
| 43 | 43 | .ext-detail { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); } |
| 44 | 44 | .ext-detail[hidden] { display: none; } |
| 45 | -.ext-applies { font-size: .74rem; color: #7ee787; margin-top: 3px; } | |
| 46 | -.ext-nothing, .ext-ignored { font-size: .72rem; color: #e5a53a; margin-top: 3px; } | |
| 45 | +.ext-ignored { font-size: .72rem; color: #e5a53a; margin-top: 3px; } | |
| 46 | +/* veredicto: primero la frase que decide (verde si funciona, ámbar si no) */ | |
| 47 | +.ext-verdict { margin-top: 4px; font-size: .74rem; line-height: 1.4; overflow-wrap: anywhere; } | |
| 48 | +.ext-v-main { font-weight: 600; color: #7ee787; } | |
| 49 | +.ext-v-partial .ext-v-main { color: #b9e08a; } | |
| 50 | +.ext-v-mostlyCode .ext-v-main, .ext-v-code .ext-v-main, .ext-v-nothing .ext-v-main { color: #e5a53a; } | |
| 51 | +.ext-v-more { color: var(--muted); margin-top: 2px; font-size: .72rem; overflow-wrap: anywhere; } | |
| 52 | +/* lo que hace ahora cada instalada */ | |
| 53 | +.ext-now { margin-top: 4px; font-size: .74rem; color: #7ee787; } | |
| 54 | +.ext-now.muted { color: var(--muted); } | |
| 55 | +.ext-now-line { overflow-wrap: anywhere; } | |
| 56 | +/* aviso tras instalar: qué cambió y dónde verlo */ | |
| 57 | +.ext-done { margin: 6px 0 0; padding: 8px 10px; border-radius: 8px; font-size: .78rem; background: var(--bg3); border: 1px solid rgba(63,185,112,.35); overflow-wrap: anywhere; } | |
| 58 | +.ext-done-h { font-weight: 700; margin-bottom: 4px; } | |
| 59 | +.ext-done-part { margin-top: 6px; } | |
| 60 | +.ext-done-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; } | |
| 61 | +.ext-done-acts button { font-size: .74rem; padding: 4px 10px; border-radius: 6px; cursor: pointer; background: none; border: 1px solid var(--line); color: var(--fg); max-width: 100%; white-space: normal; text-align: left; } | |
| 62 | +.ext-done-acts button:hover { border-color: var(--accent2); } | |
| 47 | 63 | .ext-theme-chips { margin-top: 6px; } |
| 48 | 64 | .ext-license { margin: 6px 0 0; max-height: 180px; overflow: auto; white-space: pre-wrap; font-size: .68rem; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; } |
| 49 | 65 | .ext-license[hidden] { display: none; } |
| @@ -51,7 +67,8 @@ | ||
| 51 | 67 | .ext-warn summary { cursor: pointer; } |
| 52 | 68 | .ext-warn ul { margin: 4px 0 0 18px; padding: 0; color: var(--muted); overflow-wrap: anywhere; } |
| 53 | 69 | .ext-actions { display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto; } |
| 54 | -.ext-actions button { font-size: .74rem; padding: 5px 11px; border-radius: 6px; cursor: pointer; white-space: nowrap; } | |
| 70 | +.ext-actions { max-width: 40%; } | |
| 71 | +.ext-actions button { font-size: .74rem; padding: 5px 11px; border-radius: 6px; cursor: pointer; white-space: normal; text-align: center; } | |
| 55 | 72 | .ext-actions .primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: none; color: #fff; } |
| 56 | 73 | .ext-actions .ghost { background: none; border: 1px solid var(--line); color: var(--muted); } |
| 57 | 74 | .ext-actions .ghost:hover:not(:disabled):not([aria-disabled="true"]) { color: var(--fg); border-color: var(--accent2); } |
| @@ -59,7 +76,7 @@ | ||
| 59 | 76 | .ext-more { display: block; margin: 4px auto 10px; font-size: .76rem; } |
| 60 | 77 | @media (max-width: 560px) { |
| 61 | 78 | .ext-row { flex-wrap: wrap; } |
| 62 | - .ext-actions { flex-direction: row; width: 100%; justify-content: flex-end; } | |
| 79 | + .ext-actions { flex-direction: row; width: 100%; max-width: none; justify-content: flex-end; } | |
| 63 | 80 | } |
| 64 | 81 | |
| 65 | 82 | /* selector de tema: como la paleta de comandos */ |
modified web/js/ext/host.js +35 −0
| @@ -215,6 +215,14 @@ | ||
| 215 | 215 | if (meta && v.id !== `${meta.namespace}.${meta.name}`.toLowerCase()) { |
| 216 | 216 | throw Object.assign(new Error(`el paquete dice ser ${v.id}, no ${meta.namespace}.${meta.name}`), { code: 'mismatch', got: v.id, want: `${meta.namespace}.${meta.name}` }); |
| 217 | 217 | } |
| 218 | + // lo que el usuario VERÍA: temas, snippets, resaltado de un lenguaje o los | |
| 219 | + // ajustes de uno nuevo. Un lenguaje que solo asocia extensiones de fichero | |
| 220 | + // no cambia nada en pantalla; si además el valor de la extensión es su | |
| 221 | + // código, instalarla sería inútil y se dice en vez de fingir que funciona. | |
| 222 | + const seVe = v.themes.length || v.snippets.length | |
| 223 | + || v.grammars.some(g => g.language && !(builtin.has(g.language) && !canOverride(monaco, g.language))) | |
| 224 | + || v.languages.some(l => l.config && !builtin.has(l.id)); | |
| 225 | + if (!seVe && v.analysis.hasCode) throw Object.assign(new Error('codeonly'), { code: 'codeonly', analysis: v.analysis, displayName: v.displayName }); | |
| 218 | 226 | if (!v.themes.length && !v.grammars.length && !v.snippets.length && !v.languages.length) { |
| 219 | 227 | // declaraba cosas aplicables pero ninguna se pudo leer: no es lo mismo |
| 220 | 228 | // que no traer nada, y el usuario tiene que saber por qué |
| @@ -231,6 +239,7 @@ | ||
| 231 | 239 | license: (meta?.license || v.license || '').slice(0, 200), sha256, verified, source, size: bytes.length, |
| 232 | 240 | installedAt: previo?.installedAt || Date.now(), enabled: previo ? previo.enabled : true, |
| 233 | 241 | hasCode: v.analysis.hasCode, ignored: v.analysis.ignored, pack: v.analysis.pack, warnings: v.warnings.slice(0, 20), |
| 242 | + categories: v.analysis.categories, sizes: v.analysis.sizes, webviews: v.analysis.webviews, browserEntry: v.analysis.browserEntry, | |
| 234 | 243 | themes: v.themes.map(t => { const key = k('theme/' + t.index); files.set(key, t.data); return { key, label: t.label, uiTheme: t.uiTheme, themeId: themeIdFor(v.id, t, t.index, usados) }; }), |
| 235 | 244 | grammars: v.grammars.map(g => { |
| 236 | 245 | const key = k(g.path); files.set(key, g.data); |
| @@ -286,5 +295,31 @@ | ||
| 286 | 295 | // de serie (Monaco conserva la suya) |
| 287 | 296 | grammarSkippedFor: lang => typeof lang === 'string' && builtin.has(lang) && !canOverride(monaco, lang), |
| 288 | 297 | builtinLanguage: id => builtin.has(id), |
| 298 | + // para decir en llano lo que hace cada extensión (panel.js) | |
| 299 | + languageName(id) { | |
| 300 | + for (let i = langContribs.length - 1; i >= 0; i--) if (langContribs[i].id === id && langContribs[i].aliases?.[0]) return langContribs[i].aliases[0]; | |
| 301 | + return monaco.languages.getLanguages().find(l => l.id === id)?.aliases?.[0] || null; | |
| 302 | + }, | |
| 303 | + languageExtensions(id) { | |
| 304 | + const out = new Set(); | |
| 305 | + for (const l of langContribs) if (l.id === id) for (const x of l.extensions || []) out.add(x); | |
| 306 | + for (const x of monaco.languages.getLanguages().find(l => l.id === id)?.extensions || []) out.add(x); | |
| 307 | + return [...out]; | |
| 308 | + }, | |
| 309 | + async snippetPrefixes(id, n = 3) { | |
| 310 | + const e = exts.find(x => x.id === id); | |
| 311 | + const out = []; | |
| 312 | + for (const s of e?.snippets || []) { | |
| 313 | + for (const x of (await store.getFile(s.key).catch(() => null)) || []) { | |
| 314 | + if (x?.prefix && !out.includes(x.prefix)) out.push(x.prefix); | |
| 315 | + if (out.length >= n) return out; | |
| 316 | + } | |
| 317 | + } | |
| 318 | + return out; | |
| 319 | + }, | |
| 320 | + async languageConfig(id, lang) { | |
| 321 | + const l = exts.find(x => x.id === id)?.languages?.find(x => x.id === lang); | |
| 322 | + return l?.configKey ? store.getFile(l.configKey).catch(() => null) : null; | |
| 323 | + }, | |
| 289 | 324 | }; |
| 290 | 325 | } |
modified web/js/ext/i18n.js +74 −12
| @@ -15,11 +15,44 @@ | ||
| 15 | 15 | install: 'Instalar', installing: 'Instalando…', downloading: 'Descargando… {pct}%', installedOk: 'Instalada ✓', update: 'Actualizar a {v}', |
| 16 | 16 | enable: 'Activar', disable: 'Desactivar', disabled: 'desactivada', uninstall: 'Desinstalar', confirmUninstall: '¿Desinstalar «{name}»?', |
| 17 | 17 | details: 'Detalles', loadingDetails: 'Leyendo el manifiesto…', |
| 18 | - applies: 'Aplica: {list}', ignores: 'No aplica: {list}', nothing: 'Nada de esta extensión se puede aplicar aquí.', | |
| 19 | - needsCode: 'necesita su código', notYet: 'aún no', | |
| 20 | - hasCode: 'Trae código (main/browser): no se ejecuta — haría falta un host de extensiones.', | |
| 18 | + nothing: 'Nada de esta extensión se puede aplicar aquí.', | |
| 21 | 19 | pack: 'Es un paquete de {n} extensiones: instálalas una a una.', |
| 22 | - themes: '{n} tema|{n} temas', grammars: '{n} gramática|{n} gramáticas', snippets: 'snippets ({langs})', languages: '{n} lenguaje|{n} lenguajes', | |
| 20 | + andMore: '{n} más', quoted: '«{x}»', | |
| 21 | + fFormat: 'formatear código', fLint: 'avisar de errores', fDebug: 'depurar', fPreview: 'vistas previas propias', fNotebooks: 'cuadernos', | |
| 22 | + fTesting: 'ejecutar tests', fScm: 'control de versiones', fData: 'herramientas de datos', fAI: 'asistente de IA', fKeys: 'atajos de teclado', | |
| 23 | + fLangPack: 'traducir la interfaz', fCloud: 'servicios en la nube', fCommands: 'sus propias acciones', fPanels: 'paneles propios', fTasks: 'tareas', | |
| 24 | + fSettings: 'sus ajustes', fJsonCheck: 'validar ficheros JSON', fSemantic: 'colorear según el significado del código', fIcons: 'iconos', | |
| 25 | + fTerminal: 'terminal', fAccounts: 'iniciar sesión en servicios', fWalk: 'guías de inicio', fStatus: 'avisos en la barra de estado', | |
| 26 | + fCodeActions: 'arreglos rápidos', fLangServer: 'ayudas del lenguaje', fOther: 'otras funciones', fOwn: 'lo que hace su propio código', | |
| 27 | + pThemes: 'el tema {list}|los temas {list}', pThemesCount: 'un tema de color|{n} temas de color', pHighlight: 'el resaltado de {list}', pSettings: 'comentarios y corchetes de {list}', | |
| 28 | + pSnippetsN: '{n} snippet para {list}|{n} snippets para {list}', pSnippets: 'snippets para {list}', | |
| 29 | + vFull: 'Funciona en Code: añade {list}.', vPartial: 'Funciona en parte: añade {list}.', | |
| 30 | + vMainBroken: 'Lo principal de esta extensión ({what}) no funciona en Code: necesita ejecutar su propio código.', | |
| 31 | + vOnly: 'Solo se aplicaría {list}.', | |
| 32 | + vNextVersion: 'Eso llegará con la siguiente versión de Code.', | |
| 33 | + vNever: 'Y no está previsto: usa ventanas o programas propios que Code no puede abrir.', | |
| 34 | + vMissingNext: 'No funciona: {list}. Necesita ejecutar su propio código; llegará con la siguiente versión de Code.', | |
| 35 | + vMissingNever: 'No funciona: {list}. Necesita ejecutar su propio código, y eso no está previsto en Code.', | |
| 36 | + vMissingLater: 'Aún no se aplica: {list}.', | |
| 37 | + keepsBuiltin: 'Code ya resalta {list} a su manera y lo mantiene.', | |
| 38 | + installOnlyThemes: 'Instalar solo los temas', installOnlyHighlight: 'Instalar solo el resaltado', installOnlySnippets: 'Instalar solo los snippets', | |
| 39 | + installOnlyWorking: 'Instalar solo lo que funciona', notHere: 'No funciona en Code', nothingHere: 'Nada que aplicar', | |
| 40 | + errCodeOnly: '«{name}» no se ha instalado.', | |
| 41 | + cThemeApplied: 'Tema «{name}» aplicado.', cThemeReady: 'Tema «{name}» listo para usar.', cThemesReady: '{n} temas listos: {list}.', | |
| 42 | + bApplyNow: 'Aplicar ahora', bUndo: 'Deshacer', bPickTheme: 'Elegir tema…', | |
| 43 | + cHighlight: 'Resaltado para {list}.', cHighlightOpen: 'Ya se ve en {files}, que está abierto.|Ya se ve en {files}, que están abiertos.', | |
| 44 | + cHighlightTry: 'Abre un fichero {exts} para verlo.', | |
| 45 | + bGoto: 'Ir a {file}', bOpenFile: 'Abrir {file} de ejemplo', bTry: 'Probar', bTryIn: 'Probar en {file}', | |
| 46 | + cSettings: 'En {lang}: {what}.', sComment: 'comentar con {c} (Ctrl+/)', sBrackets: 'corchetes {b}', sAutoClose: 'cierre automático de {p}', | |
| 47 | + cSnippets: '{n} snippet para {list}.|{n} snippets para {list}.', | |
| 48 | + cSnippetsTry: 'Prueba: escribe {prefixes} y elige la sugerencia con Tab o Enter.', | |
| 49 | + nThemeActive: 'Tema activo: «{name}».', nThemeIdle: 'Ningún tema suyo está activo: pulsa uno para aplicarlo.', | |
| 50 | + nHighlighting: 'Resaltando {n} fichero abierto ({list}).|Resaltando {n} ficheros abiertos ({list}).', | |
| 51 | + nHighlightIdle: 'Resalta {list}; ahora no hay ninguno abierto.', | |
| 52 | + nSnippets: '{n} snippet listo ({list}).|{n} snippets listos ({list}).', nSettings: 'Comentarios y corchetes de {list}.', | |
| 53 | + nOff: 'Desactivada: ahora no aplica nada.', | |
| 54 | + tryHighlightNamed: 'Probar el resaltado de {name}', trySnippetsNamed: 'Probar los snippets de {name}', | |
| 55 | + statusTrySnippets: 'Snippets: escribe {prefixes} y elige la sugerencia con Tab o Enter.', | |
| 23 | 56 | license: 'Licencia: {l}', viewLicense: 'ver licencia', noLicense: 'sin licencia declarada', |
| 24 | 57 | verified: 'suma SHA-256 comprobada', unverified: 'Open VSX no publica suma SHA-256', fromFile: 'desde fichero', |
| 25 | 58 | downloads: '{n} descargas', |
| @@ -40,8 +73,6 @@ | ||
| 40 | 73 | errQuota: 'No queda espacio en el almacenamiento del navegador para instalarla.', |
| 41 | 74 | err: 'No se pudo: {e}', cancelled: 'Cancelado.', |
| 42 | 75 | installedMsg: '«{name}» instalada.', |
| 43 | - grammarNotApplied: 'gramática de {lang} (Monaco conserva su coloreado de serie)', | |
| 44 | - settingsNotApplied: 'configuración de {lang} (Monaco conserva la suya)', | |
| 45 | 76 | warnSummary: '{n} parte no se pudo usar|{n} partes no se pudieron usar', |
| 46 | 77 | warn_theme: 'Tema «{name}»: {why}', warn_grammar: 'Gramática {name}: {why}', warn_snippets: 'Snippets {name}: {why}', |
| 47 | 78 | warn_config: 'Configuración de {name}: {why}', warn_regex: 'Expresión descartada en {name}, podría congelar la pestaña: {why}', |
| @@ -67,11 +98,44 @@ | ||
| 67 | 98 | install: 'Install', installing: 'Installing…', downloading: 'Downloading… {pct}%', installedOk: 'Installed ✓', update: 'Update to {v}', |
| 68 | 99 | enable: 'Enable', disable: 'Disable', disabled: 'disabled', uninstall: 'Uninstall', confirmUninstall: 'Uninstall “{name}”?', |
| 69 | 100 | details: 'Details', loadingDetails: 'Reading the manifest…', |
| 70 | - applies: 'Applies: {list}', ignores: 'Not applied: {list}', nothing: 'Nothing in this extension can be applied here.', | |
| 71 | - needsCode: 'needs its code', notYet: 'not yet', | |
| 72 | - hasCode: 'Ships code (main/browser): it does not run here — that needs an extension host.', | |
| 101 | + nothing: 'Nothing in this extension can be applied here.', | |
| 73 | 102 | pack: 'This is a pack of {n} extensions: install them one by one.', |
| 74 | - themes: '{n} theme|{n} themes', grammars: '{n} grammar|{n} grammars', snippets: 'snippets ({langs})', languages: '{n} language|{n} languages', | |
| 103 | + andMore: '{n} more', quoted: '“{x}”', | |
| 104 | + fFormat: 'formatting code', fLint: 'flagging errors', fDebug: 'debugging', fPreview: 'its own previews', fNotebooks: 'notebooks', | |
| 105 | + fTesting: 'running tests', fScm: 'version control', fData: 'data tools', fAI: 'an AI assistant', fKeys: 'keyboard shortcuts', | |
| 106 | + fLangPack: 'translating the interface', fCloud: 'cloud services', fCommands: 'its own actions', fPanels: 'its own panels', fTasks: 'tasks', | |
| 107 | + fSettings: 'its settings', fJsonCheck: 'checking JSON files', fSemantic: 'colouring by what the code means', fIcons: 'icons', | |
| 108 | + fTerminal: 'a terminal', fAccounts: 'signing in to services', fWalk: 'getting-started guides', fStatus: 'status bar items', | |
| 109 | + fCodeActions: 'quick fixes', fLangServer: 'language help', fOther: 'other features', fOwn: 'what its own code does', | |
| 110 | + pThemes: 'the theme {list}|the themes {list}', pThemesCount: 'a colour theme|{n} colour themes', pHighlight: 'highlighting for {list}', pSettings: 'comments and brackets for {list}', | |
| 111 | + pSnippetsN: '{n} snippet for {list}|{n} snippets for {list}', pSnippets: 'snippets for {list}', | |
| 112 | + vFull: 'Works in Code: adds {list}.', vPartial: 'Partly works: adds {list}.', | |
| 113 | + vMainBroken: 'The main thing this extension does ({what}) does not work in Code: it needs to run its own code.', | |
| 114 | + vOnly: 'Only {list} would apply.', | |
| 115 | + vNextVersion: 'That comes with the next version of Code.', | |
| 116 | + vNever: 'And it is not planned: it uses its own windows or programs, which Code cannot open.', | |
| 117 | + vMissingNext: 'Does not work: {list}. It needs to run its own code; that comes with the next version of Code.', | |
| 118 | + vMissingNever: 'Does not work: {list}. It needs to run its own code, and that is not planned for Code.', | |
| 119 | + vMissingLater: 'Not applied yet: {list}.', | |
| 120 | + keepsBuiltin: 'Code already highlights {list} its own way and keeps it.', | |
| 121 | + installOnlyThemes: 'Install only the themes', installOnlyHighlight: 'Install only the highlighting', installOnlySnippets: 'Install only the snippets', | |
| 122 | + installOnlyWorking: 'Install only what works', notHere: 'Does not work in Code', nothingHere: 'Nothing to apply', | |
| 123 | + errCodeOnly: '“{name}” was not installed.', | |
| 124 | + cThemeApplied: 'Theme “{name}” applied.', cThemeReady: 'Theme “{name}” is ready to use.', cThemesReady: '{n} themes ready: {list}.', | |
| 125 | + bApplyNow: 'Apply now', bUndo: 'Undo', bPickTheme: 'Choose theme…', | |
| 126 | + cHighlight: 'Syntax highlighting for {list}.', cHighlightOpen: 'Already visible in {files}, which is open.|Already visible in {files}, which are open.', | |
| 127 | + cHighlightTry: 'Open a {exts} file to see it.', | |
| 128 | + bGoto: 'Go to {file}', bOpenFile: 'Open {file} as an example', bTry: 'Try it', bTryIn: 'Try in {file}', | |
| 129 | + cSettings: 'In {lang}: {what}.', sComment: 'comment with {c} (Ctrl+/)', sBrackets: 'brackets {b}', sAutoClose: 'auto-closing {p}', | |
| 130 | + cSnippets: '{n} snippet for {list}.|{n} snippets for {list}.', | |
| 131 | + cSnippetsTry: 'Try it: type {prefixes} and pick the suggestion with Tab or Enter.', | |
| 132 | + nThemeActive: 'Active theme: “{name}”.', nThemeIdle: 'None of its themes is active: click one to apply it.', | |
| 133 | + nHighlighting: 'Highlighting {n} open file ({list}).|Highlighting {n} open files ({list}).', | |
| 134 | + nHighlightIdle: 'Highlights {list}; none is open right now.', | |
| 135 | + nSnippets: '{n} snippet ready ({list}).|{n} snippets ready ({list}).', nSettings: 'Comments and brackets for {list}.', | |
| 136 | + nOff: 'Disabled: nothing applied right now.', | |
| 137 | + tryHighlightNamed: 'Try the {name} highlighting', trySnippetsNamed: 'Try the {name} snippets', | |
| 138 | + statusTrySnippets: 'Snippets: type {prefixes} and pick the suggestion with Tab or Enter.', | |
| 75 | 139 | license: 'Licence: {l}', viewLicense: 'view licence', noLicense: 'no licence declared', |
| 76 | 140 | verified: 'SHA-256 checked', unverified: 'Open VSX publishes no SHA-256', fromFile: 'from file', |
| 77 | 141 | downloads: '{n} downloads', |
| @@ -92,8 +156,6 @@ | ||
| 92 | 156 | errQuota: 'There is no browser storage left to install it.', |
| 93 | 157 | err: 'Could not do it: {e}', cancelled: 'Cancelled.', |
| 94 | 158 | installedMsg: '“{name}” installed.', |
| 95 | - grammarNotApplied: '{lang} grammar (Monaco keeps its built-in highlighting)', | |
| 96 | - settingsNotApplied: '{lang} settings (Monaco keeps its own)', | |
| 97 | 159 | warnSummary: '{n} part could not be used|{n} parts could not be used', |
| 98 | 160 | warn_theme: 'Theme “{name}”: {why}', warn_grammar: 'Grammar {name}: {why}', warn_snippets: 'Snippets {name}: {why}', |
| 99 | 161 | warn_config: 'Settings for {name}: {why}', warn_regex: 'Expression discarded in {name}, it could freeze the tab: {why}', |
modified web/js/ext/openvsx.js +6 −0
| @@ -62,6 +62,12 @@ | ||
| 62 | 62 | return getJson(meta.files.manifest, signal); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | +// El package.json de un resultado de búsqueda, sin pedir antes sus metadatos: | |
| 66 | +// una sola petición por fila para decir qué haría antes de instalarla. | |
| 67 | +export function manifestOf({ namespace, name, version }, { signal } = {}) { | |
| 68 | + return getJson(`${BASE}/api/${seg(namespace)}/${seg(name)}/${seg(version)}/file/package.json`, signal); | |
| 69 | +} | |
| 70 | + | |
| 65 | 71 | export async function text(url, { signal, max = 200_000 } = {}) { |
| 66 | 72 | const u = deOpenVsx(url); |
| 67 | 73 | if (!u) throw new OpenVsxError('URL fuera de Open VSX', 'http'); |
modified web/js/ext/panel.js +338 −54
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | // <summary>), los resultados y avisos se anuncian (role=status/alert), el |
| 9 | 9 | // foco no se pierde al repintar ni al cerrar, y Escape cierra el panel. |
| 10 | 10 | import { tx } from './i18n.js'; |
| 11 | +import { describe, lista, listaO, esTexto } from './verdict.js'; | |
| 11 | 12 | |
| 12 | 13 | const $ = id => document.getElementById(id); |
| 13 | 14 | const el = (tag, cls, txt) => { const e = document.createElement(tag); if (cls) e.className = cls; if (txt != null) e.textContent = txt; return e; }; |
| @@ -21,6 +22,7 @@ | ||
| 21 | 22 | let abridor = null; // quién tenía el foco al abrir el panel |
| 22 | 23 | let focoPendiente = null; // control a recuperar tras repintar «Instaladas» |
| 23 | 24 | let nDetalle = 0; |
| 25 | +let ideCargado = null; // ../ide.js, para contar pestañas al pintar «Instaladas» | |
| 24 | 26 | |
| 25 | 27 | function ponCss() { |
| 26 | 28 | if (cssPuesto) return; |
| @@ -57,6 +59,7 @@ | ||
| 57 | 59 | if (!$('ext-panel')?.isConnected || box.hidden) abridor = document.activeElement; |
| 58 | 60 | estado.msg = null; // un aviso viejo no se repite al volver a abrir |
| 59 | 61 | pinta(); |
| 62 | + if (!ideCargado) ide().then(m => { ideCargado = m; if ($('ext-panel')?.isConnected) pintaInstaladas(); }); | |
| 60 | 63 | } |
| 61 | 64 | |
| 62 | 65 | function cierraPanel() { |
| @@ -70,7 +73,7 @@ | ||
| 70 | 73 | // ── mensajes legibles (exportados para las pruebas en Node) ── |
| 71 | 74 | const ERRORES = { |
| 72 | 75 | rate: 'errRate', sha: 'errSha', nothing: 'errNothing', notvsix: 'errNotVsix', notfound: 'errNotFound', |
| 73 | - big: 'errBig', noname: 'errNoName', blocked: 'errBlocked', | |
| 76 | + big: 'errBig', noname: 'errNoName', blocked: 'errBlocked', codeonly: 'notHere', | |
| 74 | 77 | }; |
| 75 | 78 | export function textoError(e) { |
| 76 | 79 | const code = e?.code; |
| @@ -115,6 +118,7 @@ | ||
| 115 | 118 | m.hidden = false; |
| 116 | 119 | m.textContent = texto || ''; |
| 117 | 120 | m.classList.toggle('err', !!error); |
| 121 | + m.classList.remove('ext-msg-sr'); | |
| 118 | 122 | } |
| 119 | 123 | // Estado de la búsqueda para el lector de pantalla (la cabecera visible se |
| 120 | 124 | // rehace en cada repintado y no podría anunciarse). |
| @@ -126,34 +130,76 @@ | ||
| 126 | 130 | // «Aplica: 2 temas · No aplica: commands (necesita su código)», con lo que de |
| 127 | 131 | // verdad se aplicaría aquí: la gramática de un lenguaje de serie sin Monarch |
| 128 | 132 | // (JSON) y la configuración de un lenguaje de serie no se aplican, y no cuentan. |
| 129 | -function resumen({ themes = 0, grammarLangs = [], languageList = [], snippetLangs = [], ignored = [], hasCode = false, pack = [] }) { | |
| 130 | - const saltaGram = l => !!l && !!host.grammarSkippedFor?.(l); | |
| 133 | +// ── qué hace cada extensión, en llano (verdict.js) ── | |
| 134 | +const BONITOS = { | |
| 135 | + javascript: 'JavaScript', typescript: 'TypeScript', javascriptreact: 'JavaScript React', typescriptreact: 'TypeScript React', | |
| 136 | + html: 'HTML', css: 'CSS', scss: 'SCSS', less: 'Less', json: 'JSON', jsonc: 'JSON', vue: 'Vue', python: 'Python', markdown: 'Markdown', | |
| 137 | + shellscript: 'Shell', go: 'Go', rust: 'Rust', java: 'Java', php: 'PHP', ruby: 'Ruby', csharp: 'C#', cpp: 'C++', c: 'C', yaml: 'YAML', | |
| 138 | +}; | |
| 139 | +function nombreLenguaje(id, langs = []) { | |
| 140 | + return langs.find(l => l.id === id && esTexto(l.name))?.name || host?.languageName?.(id) || BONITOS[id] || id; | |
| 141 | +} | |
| 142 | +function extsDe(id, langs = []) { | |
| 143 | + const propias = langs.filter(l => l.id === id).flatMap(l => l.extensions || []); | |
| 144 | + return [...new Set(propias.length ? propias : host?.languageExtensions?.(id) || [])]; | |
| 145 | +} | |
| 146 | +// Hechos comunes a un package.json (antes de instalar) y a un registro instalado. | |
| 147 | +function hechos(base, { themes = [], grammarLangs = [], langs = [], snippets = [] }) { | |
| 148 | + const salta = l => !!host.grammarSkippedFor?.(l); | |
| 131 | 149 | const deSerie = id => !!host.builtinLanguage?.(id); |
| 132 | - const gramSaltadas = [...new Set(grammarLangs.filter(saltaGram))]; | |
| 133 | - const confSaltadas = [...new Set(languageList.filter(l => l.config && deSerie(l.id)).map(l => l.id))]; | |
| 134 | - const grammars = grammarLangs.filter(l => !saltaGram(l)).length; | |
| 135 | - const languages = languageList.filter(l => !deSerie(l.id)).length; | |
| 136 | - const aplica = []; | |
| 137 | - if (themes) aplica.push(tx('themes', { n: themes })); | |
| 138 | - if (grammars) aplica.push(tx('grammars', { n: grammars })); | |
| 139 | - if (languages) aplica.push(tx('languages', { n: languages })); | |
| 140 | - if (snippetLangs.length) aplica.push(tx('snippets', { langs: snippetLangs.slice(0, 6).join(', ') + (snippetLangs.length > 6 ? '…' : '') })); | |
| 141 | - const porMotivo = { code: [], later: [] }; | |
| 142 | - for (const i of ignored) (porMotivo[i.why] || porMotivo.later).push(i.key); | |
| 143 | - const no = [...gramSaltadas.map(lang => tx('grammarNotApplied', { lang })), ...confSaltadas.map(lang => tx('settingsNotApplied', { lang }))]; | |
| 144 | - if (porMotivo.code.length) no.push(`${porMotivo.code.join(', ')} (${tx('needsCode')})`); | |
| 145 | - if (porMotivo.later.length) no.push(`${porMotivo.later.join(', ')} (${tx('notYet')})`); | |
| 146 | - const lineas = []; | |
| 147 | - lineas.push(aplica.length ? { cls: 'ext-applies', t: tx('applies', { list: aplica.join(' · ') }) } : { cls: 'ext-nothing', t: tx('nothing') }); | |
| 148 | - if (no.length) lineas.push({ cls: 'ext-ignored', t: tx('ignores', { list: no.join(' · ') }) }); | |
| 149 | - if (hasCode) lineas.push({ cls: 'ext-ignored', t: tx('hasCode') }); | |
| 150 | - if (pack.length) lineas.push({ cls: 'ext-ignored', t: tx('pack', { n: pack.length }) }); | |
| 151 | - return { lineas, any: aplica.length > 0 }; | |
| 152 | -} | |
| 153 | - | |
| 154 | -// Botón de acción: texto visible y nombre accesible con la extensión | |
| 155 | -// («Instalar Monokai»). Sin nombre accesible, el lector lee el texto visible | |
| 156 | -// (el progreso de la descarga, por ejemplo). | |
| 150 | + const conGram = [...new Set(grammarLangs.filter(l => l && !salta(l)))]; | |
| 151 | + // snippets de un lenguaje que Code no tiene (javascriptreact, vue…) no | |
| 152 | + // saldrían nunca: ni se cuentan ni se prometen. Y un mismo fichero que sirve | |
| 153 | + // a varios lenguajes se cuenta una vez. | |
| 154 | + const existe = id => langs.some(l => l.id === id) || !!host.languageName?.(id) || !!host.builtinLanguage?.(id); | |
| 155 | + const porLang = new Map(); | |
| 156 | + const vistos = new Set(); | |
| 157 | + for (const s of snippets.filter(x => existe(x.language))) { | |
| 158 | + const n = !Number.isFinite(s.count) ? NaN : s.key && vistos.has(s.key) ? 0 : s.count; | |
| 159 | + if (s.key) vistos.add(s.key); | |
| 160 | + porLang.set(s.language, (porLang.has(s.language) ? porLang.get(s.language) : 0) + n); | |
| 161 | + } | |
| 162 | + return { | |
| 163 | + ...base, themes, | |
| 164 | + highlight: conGram.map(id => ({ id, name: nombreLenguaje(id, langs), exts: extsDe(id, langs) })), | |
| 165 | + settingsOnly: langs.filter(l => l.config && !deSerie(l.id) && !conGram.includes(l.id)).map(l => nombreLenguaje(l.id, langs)), | |
| 166 | + keepsBuiltin: [...new Set(grammarLangs.filter(l => l && salta(l)))].map(id => nombreLenguaje(id, langs)), | |
| 167 | + snippets: [...porLang].map(([id, n]) => ({ id, name: nombreLenguaje(id, langs), count: Number.isFinite(n) ? n : null })), | |
| 168 | + }; | |
| 169 | +} | |
| 170 | +function hechosDeManifiesto(a) { | |
| 171 | + return hechos({ hasCode: a.hasCode, browserEntry: a.browserEntry, categories: a.categories || [], sizes: a.sizes || {}, webviews: a.webviews, ignored: a.ignored || [], pack: a.pack || [] }, { | |
| 172 | + themes: a.themeLabels || [], grammarLangs: a.grammarLangs || [], langs: a.languageList || [], | |
| 173 | + snippets: (a.snippetLangs || []).map(language => ({ language, count: null })), | |
| 174 | + }); | |
| 175 | +} | |
| 176 | +function hechosDeRegistro(e) { | |
| 177 | + // registros de antes de guardar categorías: se asume que lo que se aplica es lo principal | |
| 178 | + const categories = e.categories || ['Programming Languages']; | |
| 179 | + return hechos({ hasCode: e.hasCode, browserEntry: !!e.browserEntry, categories, sizes: e.sizes || {}, webviews: e.webviews, ignored: e.ignored || [], pack: e.pack || [] }, { | |
| 180 | + themes: (e.themes || []).map(t => t.label), grammarLangs: (e.grammars || []).map(g => g.language ?? null), | |
| 181 | + langs: (e.languages || []).map(l => ({ id: l.id, name: l.aliases?.[0], extensions: l.extensions || [], config: !!l.configKey })), | |
| 182 | + snippets: (e.snippets || []).map(s => ({ language: s.language, key: s.key, count: Number.isFinite(s.count) ? s.count : null })), | |
| 183 | + }); | |
| 184 | +} | |
| 185 | +// El bloque del veredicto: primero la frase que decide, luego el detalle. | |
| 186 | +function bloqueVeredicto(f, v, { principal = true } = {}) { | |
| 187 | + const box = el('div', 'ext-verdict ext-v-' + v.kind); | |
| 188 | + box.id = 'ext-v-' + (++nDetalle); | |
| 189 | + if (principal || v.kind === 'code' || v.kind === 'nothing') box.appendChild(el('div', 'ext-v-main', v.verdict)); | |
| 190 | + for (const l of v.lines) box.appendChild(el('div', 'ext-v-more', l)); | |
| 191 | + if (f.keepsBuiltin?.length) box.appendChild(el('div', 'ext-v-more', tx('keepsBuiltin', { list: lista(f.keepsBuiltin) }))); | |
| 192 | + if (f.pack?.length) box.appendChild(el('div', 'ext-v-more', tx('pack', { n: f.pack.length }))); | |
| 193 | + return box; | |
| 194 | +} | |
| 195 | +// El botón de instalar dice lo que vas a tener; si no se ve nada, no se ofrece. | |
| 196 | +function botonSegunVeredicto(b, v, nombre) { | |
| 197 | + const texto = tx(v.button.key); | |
| 198 | + rotula(b, texto, v.button.key === 'install' ? tx('installNamed', { name: nombre }) : `${texto}: ${nombre}`); | |
| 199 | + b.className = (v.button.style === 'primary' ? 'primary' : 'ghost') + ' ext-install'; | |
| 200 | + inerte(b, v.button.disabled); | |
| 201 | +} | |
| 202 | + | |
| 157 | 203 | function rotula(b, texto, accesible = null) { |
| 158 | 204 | b.textContent = texto; |
| 159 | 205 | if (accesible) b.setAttribute('aria-label', accesible); else b.removeAttribute('aria-label'); |
| @@ -330,6 +376,47 @@ | ||
| 330 | 376 | return letra; |
| 331 | 377 | } |
| 332 | 378 | |
| 379 | +// ── análisis previo de cada resultado: su package.json (una petición por fila, | |
| 380 | +// cuatro a la vez, en caché) para dar el veredicto ANTES de instalar ── | |
| 381 | +const analisis = new Map(); | |
| 382 | +const colaAnalisis = []; | |
| 383 | +let analizando = 0; | |
| 384 | +const claveDe = it => `${it.namespace}.${it.name}@${it.version}`; | |
| 385 | +function bombea() { | |
| 386 | + while (analizando < 4 && colaAnalisis.length) { | |
| 387 | + const { it, res, rej } = colaAnalisis.shift(); | |
| 388 | + analizando++; | |
| 389 | + (async () => { | |
| 390 | + const ovsx = await import('./openvsx.js'); | |
| 391 | + const { analyzeManifest } = await import('./vsix.js'); | |
| 392 | + return analyzeManifest(await ovsx.manifestOf(it)); | |
| 393 | + })().then(res, rej).finally(() => { analizando--; bombea(); }); | |
| 394 | + } | |
| 395 | +} | |
| 396 | +function analiza(it) { | |
| 397 | + const k = claveDe(it); | |
| 398 | + if (!analisis.has(k)) { | |
| 399 | + const p = new Promise((res, rej) => { colaAnalisis.push({ it, res, rej }); bombea(); }); | |
| 400 | + analisis.set(k, p); | |
| 401 | + p.catch(() => analisis.delete(k)); // se reintenta la próxima vez | |
| 402 | + } | |
| 403 | + return analisis.get(k); | |
| 404 | +} | |
| 405 | +function pintaVeredictoFila(row, it, a, instalada) { | |
| 406 | + const f = hechosDeManifiesto(a); | |
| 407 | + const v = describe(f); | |
| 408 | + const sitio = row.querySelector('.ext-verdict-slot'); | |
| 409 | + if (!sitio) return v; | |
| 410 | + const bloque = bloqueVeredicto(f, v); | |
| 411 | + sitio.replaceChildren(bloque); | |
| 412 | + const b = row.querySelector('.ext-install'); | |
| 413 | + if (b && !instalada && !b.dataset.ocupado) { | |
| 414 | + botonSegunVeredicto(b, v, it.displayName); | |
| 415 | + if (v.button.disabled) { b.setAttribute('aria-describedby', bloque.id); b.title = v.verdict; } else { b.removeAttribute('aria-describedby'); b.removeAttribute('title'); } | |
| 416 | + } | |
| 417 | + return v; | |
| 418 | +} | |
| 419 | + | |
| 333 | 420 | function filaResultado(it, instalada) { |
| 334 | 421 | const row = el('div', 'ext-row'); |
| 335 | 422 | row.dataset.id = `${it.namespace}.${it.name}`; |
| @@ -337,8 +424,6 @@ | ||
| 337 | 424 | const det = el('div', 'ext-detail'); |
| 338 | 425 | det.id = 'ext-det-' + (++nDetalle); |
| 339 | 426 | det.hidden = true; |
| 340 | - // el nombre es el botón que despliega el detalle (qué aplicaría y qué no): | |
| 341 | - // antes de instalar, también con teclado | |
| 342 | 427 | const t = el('div', 'ext-title'); |
| 343 | 428 | const nombre = el('button', 'ext-name', it.displayName); |
| 344 | 429 | nombre.type = 'button'; |
| @@ -349,6 +434,7 @@ | ||
| 349 | 434 | t.append(nombre, el('span', 'muted', ` ${it.namespace} · v${it.version}`)); |
| 350 | 435 | if (it.verified) t.appendChild(el('span', 'ext-badge', '✓')); |
| 351 | 436 | main.append(t, el('div', 'ext-desc', it.description)); |
| 437 | + main.appendChild(el('div', 'ext-verdict-slot')); | |
| 352 | 438 | main.appendChild(el('div', 'ext-meta muted', tx('downloads', { n: it.downloadCount.toLocaleString() }))); |
| 353 | 439 | main.appendChild(det); |
| 354 | 440 | main.onclick = e => { if (!e.target.closest('button, a, summary')) detalle(it, det, nombre); }; |
| @@ -365,6 +451,7 @@ | ||
| 365 | 451 | b.onclick = e => { e.stopPropagation(); if (!esInerte(b)) instala(it, b); }; |
| 366 | 452 | acc.appendChild(b); |
| 367 | 453 | row.append(icono(it.icon, it.displayName), main, acc); |
| 454 | + analiza(it).then(a => pintaVeredictoFila(row, it, a, instalada)).catch(() => { /* sin veredicto: el botón de siempre */ }); | |
| 368 | 455 | return row; |
| 369 | 456 | } |
| 370 | 457 | |
| @@ -375,12 +462,13 @@ | ||
| 375 | 462 | det.replaceChildren(el('div', 'muted', tx('loadingDetails'))); |
| 376 | 463 | try { |
| 377 | 464 | const ovsx = await import('./openvsx.js'); |
| 378 | - const { analyzeManifest } = await import('./vsix.js'); | |
| 379 | 465 | const meta = await ovsx.metadata(it.namespace, it.name, it.version); |
| 380 | - const a = analyzeManifest(await ovsx.manifest(meta)); | |
| 381 | - const r = resumen({ themes: a.applies.themes, grammarLangs: a.grammarLangs, languageList: a.languageList, snippetLangs: a.snippetLangs, ignored: a.ignored, hasCode: a.hasCode, pack: a.pack }); | |
| 466 | + const a = await analiza(it); | |
| 467 | + const f = hechosDeManifiesto(a); | |
| 468 | + const v = describe(f); | |
| 382 | 469 | det.replaceChildren(); |
| 383 | - for (const l of r.lineas) det.appendChild(el('div', l.cls, l.t)); | |
| 470 | + // el veredicto ya va en la fila; aquí, además, todo lo que no funcionaría | |
| 471 | + if (v.missing.length && v.kind !== 'partial') det.appendChild(el('div', 'ext-v-more', tx(v.future === 'next' ? 'vMissingNext' : 'vMissingNever', { list: lista(v.missing) }))); | |
| 384 | 472 | const lic = el('div', 'ext-meta muted', tx('license', { l: meta.license || tx('noLicense') }) + ' '); |
| 385 | 473 | if (meta.files.license) { |
| 386 | 474 | const a2 = el('a', null, tx('viewLicense')); |
| @@ -391,32 +479,190 @@ | ||
| 391 | 479 | } |
| 392 | 480 | det.appendChild(lic); |
| 393 | 481 | det.dataset.listo = '1'; |
| 394 | - // nada aplicable: instalarla solo daría un error, mejor decirlo en el botón | |
| 395 | - const inst = det.closest('.ext-row')?.querySelector('.ext-install'); | |
| 396 | - if (!r.any && inst && !esInerte(inst)) { inerte(inst, true); inst.title = tx('nothing'); inst.className = 'ghost ext-install'; } | |
| 482 | + const fila = det.closest('.ext-row'); | |
| 483 | + if (fila) pintaVeredictoFila(fila, it, a, host.list().find(e => e.id === `${it.namespace}.${it.name}`.toLowerCase())); | |
| 397 | 484 | } catch (e) { det.replaceChildren(el('div', 'ext-ignored', textoError(e))); } |
| 398 | 485 | } |
| 399 | 486 | |
| 487 | +// «No se ha instalado», con el porqué en llano. | |
| 488 | +function textoNoInstalada(nombre, a) { | |
| 489 | + const v = describe(hechosDeManifiesto(a)); | |
| 490 | + return [tx('errCodeOnly', { name: nombre }), v.verdict, ...v.lines].join(' '); | |
| 491 | +} | |
| 492 | + | |
| 400 | 493 | async function instala(src, boton) { |
| 401 | - const nombre = src instanceof Blob ? src.name : src.displayName; | |
| 494 | + const esFichero = src instanceof Blob; | |
| 495 | + const nombre = esFichero ? src.name : src.displayName; | |
| 496 | + if (!esFichero) { | |
| 497 | + // sin veredicto todavía (red lenta): se pide ahora, y si no se vería nada, no se baja | |
| 498 | + const a = await analiza(src).catch(() => null); | |
| 499 | + if (a) { | |
| 500 | + const fila = boton?.closest('.ext-row'); | |
| 501 | + const v = fila ? pintaVeredictoFila(fila, src, a, null) : describe(hechosDeManifiesto(a)); | |
| 502 | + if (v.button.disabled) { aviso(textoNoInstalada(nombre, a), true); return; } | |
| 503 | + } | |
| 504 | + } | |
| 402 | 505 | const original = boton ? { texto: boton.textContent, accesible: boton.getAttribute('aria-label') } : null; |
| 403 | - if (boton) { inerte(boton, true); rotula(boton, tx('installing')); } | |
| 506 | + if (boton) { inerte(boton, true); boton.dataset.ocupado = '1'; rotula(boton, tx('installing')); } | |
| 404 | 507 | aviso(null); |
| 508 | + $('ext-done')?.remove(); | |
| 509 | + const temaAntes = host.currentTheme(); | |
| 405 | 510 | try { |
| 406 | - const rec = await host.install(src instanceof Blob ? src : { namespace: src.namespace, name: src.name, version: src.version }, { | |
| 511 | + const rec = await host.install(esFichero ? src : { namespace: src.namespace, name: src.name, version: src.version }, { | |
| 407 | 512 | onProgress: (n, total) => { if (boton && total) boton.textContent = tx('downloading', { pct: Math.round(n / total * 100) }); }, |
| 408 | 513 | confirmLarge: async mb => confirm(tx('bigConfirm', { mb })), |
| 409 | 514 | }); |
| 410 | - if (boton) { rotula(boton, tx('installedOk'), tx('installedNamed', { name: rec.displayName || nombre })); boton.className = 'ghost ext-install'; } | |
| 515 | + if (boton) { delete boton.dataset.ocupado; rotula(boton, tx('installedOk'), tx('installedNamed', { name: rec.displayName || nombre })); boton.className = 'ghost ext-install'; } | |
| 516 | + // una extensión que solo trae temas se ve al instante: se aplica el primero | |
| 517 | + // (con «Deshacer» en el aviso) | |
| 518 | + const soloTemas = rec.themes?.length && !rec.grammars?.length && !rec.snippets?.length && !(rec.languages || []).some(l => l.configKey && !host.builtinLanguage?.(l.id)); | |
| 519 | + let auto = false; | |
| 520 | + if (soloTemas && !rec.themes.some(t => t.themeId === host.currentTheme()) && rec.enabled !== false && !host.paused) { | |
| 521 | + await host.setTheme(rec.themes[0].themeId); | |
| 522 | + auto = true; | |
| 523 | + } | |
| 411 | 524 | const nAvisos = avisosVisibles(rec.warnings).length; |
| 412 | - aviso(tx('installedMsg', { name: rec.displayName || nombre }) + (nAvisos ? ' ' + tx('warnSummary', { n: nAvisos }) + '.' : '')); | |
| 525 | + const primera = auto ? ' ' + tx('cThemeApplied', { name: rec.themes[0].label }) : ''; | |
| 526 | + aviso(tx('installedMsg', { name: rec.displayName || nombre }) + primera + (nAvisos ? ' ' + tx('warnSummary', { n: nAvisos }) + '.' : '')); | |
| 527 | + await pintaTarjeta(rec, { previo: auto ? temaAntes : null }); | |
| 528 | + pintaInstaladas(); | |
| 413 | 529 | } catch (e) { |
| 414 | - if (boton) { inerte(boton, false); rotula(boton, original.texto, original.accesible); } | |
| 415 | - aviso(textoError(e), true); | |
| 530 | + if (boton) { delete boton.dataset.ocupado; inerte(boton, false); rotula(boton, original.texto, original.accesible); } | |
| 531 | + if (e?.code === 'codeonly') { | |
| 532 | + aviso(textoNoInstalada(e.displayName || nombre, e.analysis), true); | |
| 533 | + if (boton) { const v = describe(hechosDeManifiesto(e.analysis)); botonSegunVeredicto(boton, v, nombre); } | |
| 534 | + } else aviso(textoError(e), true); | |
| 535 | + } | |
| 536 | +} | |
| 537 | + | |
| 538 | +// ── después de instalar: qué cambió, dónde verlo y un botón para probarlo ── | |
| 539 | +const baseName = p => String(p).split('/').pop(); | |
| 540 | +const cita = x => tx('quoted', { x }); | |
| 541 | +async function ide() { try { return await import('../ide.js'); } catch { return null; } } | |
| 542 | +async function ficherosDelProyecto() { try { return await (await import('../tools/code.js')).fileList(); } catch { return []; } } | |
| 543 | +function pestañasCon(ideMod, langs) { | |
| 544 | + const ids = new Set(langs); | |
| 545 | + return (ideMod?.openTabs?.() || []).filter(t => ids.has(t.language) || ids.has(host.languageForPath?.(t.path))); | |
| 546 | +} | |
| 547 | +async function ficheroCon(ideMod, langs) { | |
| 548 | + const ids = new Set(langs); | |
| 549 | + const abiertas = pestañasCon(ideMod, langs); | |
| 550 | + if (abiertas.length) return { path: (abiertas.find(t => t.active) || abiertas[0]).path, abierta: true }; | |
| 551 | + for (const f of await ficherosDelProyecto()) if (ids.has(host.languageForPath?.(f) || ideMod?.languageOfPath?.(f))) return { path: f, abierta: false }; | |
| 552 | + return null; | |
| 553 | +} | |
| 554 | +async function irA(path, { foco = true } = {}) { | |
| 555 | + const m = await ide(); | |
| 556 | + cierraPanel(); | |
| 557 | + await m?.openFile(path); | |
| 558 | + if (foco) m?.focusEditor(); | |
| 559 | +} | |
| 560 | +async function pruebaSnippets(rec, objetivo) { | |
| 561 | + const prefijos = await host.snippetPrefixes(rec.id).catch(() => []); | |
| 562 | + const pista = tx('statusTrySnippets', { prefixes: listaO(prefijos.map(cita)) }); | |
| 563 | + if (!objetivo) { aviso(pista); return; } | |
| 564 | + await irA(objetivo); | |
| 565 | + const sb = document.getElementById('statusbar'); | |
| 566 | + if (sb) sb.textContent = pista; | |
| 567 | +} | |
| 568 | +async function pruebaResaltado(langs) { | |
| 569 | + const m = await ide(); | |
| 570 | + const f = await ficheroCon(m, langs); | |
| 571 | + if (f) { await irA(f.path); return; } | |
| 572 | + aviso(tx('cHighlightTry', { exts: lista(langs.flatMap(l => extsDe(l)).slice(0, 4)) })); | |
| 573 | +} | |
| 574 | +function resumenAjustes(conf) { | |
| 575 | + if (!conf || typeof conf !== 'object') return []; | |
| 576 | + const que = []; | |
| 577 | + const lc = conf.comments?.lineComment, bc = conf.comments?.blockComment; | |
| 578 | + if (typeof lc === 'string') que.push(tx('sComment', { c: lc })); | |
| 579 | + else if (Array.isArray(bc) && bc.length === 2) que.push(tx('sComment', { c: bc.join(' … ') })); | |
| 580 | + const par = p => (Array.isArray(p) ? p[0] + p[1] : p && typeof p.open === 'string' ? p.open + p.close : null); | |
| 581 | + if (Array.isArray(conf.brackets) && conf.brackets.length) que.push(tx('sBrackets', { b: conf.brackets.map(par).filter(Boolean).slice(0, 4).join(' ') })); | |
| 582 | + if (Array.isArray(conf.autoClosingPairs) && conf.autoClosingPairs.length) que.push(tx('sAutoClose', { p: conf.autoClosingPairs.map(par).filter(Boolean).slice(0, 5).join(' ') })); | |
| 583 | + return que; | |
| 584 | +} | |
| 585 | + | |
| 586 | +async function pintaTarjeta(rec, { previo = null } = {}) { | |
| 587 | + const sitio = $('ext-msg'); | |
| 588 | + if (!sitio) return; | |
| 589 | + const m = await ide(); | |
| 590 | + const f = hechosDeRegistro(rec); | |
| 591 | + const v = describe(f); | |
| 592 | + const box = el('section', 'ext-done'); | |
| 593 | + box.id = 'ext-done'; | |
| 594 | + box.setAttribute('aria-labelledby', 'ext-done-h'); | |
| 595 | + const h = el('div', 'ext-done-h', tx('installedMsg', { name: rec.displayName })); | |
| 596 | + h.id = 'ext-done-h'; | |
| 597 | + box.appendChild(h); | |
| 598 | + const parte = () => { const p = el('div', 'ext-done-part'); box.appendChild(p); return p; }; | |
| 599 | + const botones = p => { const x = el('div', 'ext-done-acts'); p.appendChild(x); return x; }; | |
| 600 | + const boton = (fila, texto, act, fn, accesible = null) => { | |
| 601 | + const b = el('button', 'ghost', texto); | |
| 602 | + b.type = 'button'; | |
| 603 | + b.dataset.act = act; | |
| 604 | + if (accesible) b.setAttribute('aria-label', accesible); | |
| 605 | + b.onclick = fn; | |
| 606 | + fila.appendChild(b); | |
| 607 | + return b; | |
| 608 | + }; | |
| 609 | + | |
| 610 | + if (rec.themes?.length) { | |
| 611 | + const p = parte(); | |
| 612 | + const pinta = (enfoca = null) => { | |
| 613 | + p.replaceChildren(); | |
| 614 | + const activo = rec.themes.find(t => t.themeId === host.currentTheme()); | |
| 615 | + p.appendChild(el('div', null, activo ? tx('cThemeApplied', { name: activo.label }) | |
| 616 | + : rec.themes.length === 1 ? tx('cThemeReady', { name: rec.themes[0].label }) : tx('cThemesReady', { n: rec.themes.length, list: lista(rec.themes.map(t => cita(t.label))) }))); | |
| 617 | + const fila = botones(p); | |
| 618 | + if (activo && previo && previo !== activo.themeId) boton(fila, tx('bUndo'), 'undo-theme', async () => { await host.setTheme(previo); pinta('apply-theme'); pintaInstaladas(); }); | |
| 619 | + if (!activo) boton(fila, tx('bApplyNow'), 'apply-theme', async () => { await host.setTheme(rec.themes[0].themeId); pinta('undo-theme'); pintaInstaladas(); }); | |
| 620 | + boton(fila, tx('bPickTheme'), 'pick-theme', () => openThemePicker(host)); | |
| 621 | + if (enfoca) (fila.querySelector(`[data-act="${enfoca}"]`) || fila.querySelector('button'))?.focus(); | |
| 622 | + }; | |
| 623 | + pinta(); | |
| 624 | + } | |
| 625 | + | |
| 626 | + if (f.highlight.length) { | |
| 627 | + const p = parte(); | |
| 628 | + const ids = f.highlight.map(x => x.id); | |
| 629 | + p.appendChild(el('div', null, tx('cHighlight', { list: lista(f.highlight.map(x => x.name + (x.exts.length ? ` (${x.exts.slice(0, 3).join(', ')})` : ''))) }))); | |
| 630 | + const abiertas = pestañasCon(m, ids); | |
| 631 | + if (abiertas.length) { | |
| 632 | + p.appendChild(el('div', null, tx('cHighlightOpen', { n: abiertas.length, files: lista(abiertas.slice(0, 3).map(t => baseName(t.path))) }))); | |
| 633 | + const destino = abiertas.find(t => t.active) || abiertas[0]; | |
| 634 | + boton(botones(p), tx('bGoto', { file: baseName(destino.path) }), 'goto', () => irA(destino.path)); | |
| 635 | + } else { | |
| 636 | + const fich = await ficheroCon(m, ids); | |
| 637 | + if (fich) boton(botones(p), tx('bOpenFile', { file: baseName(fich.path) }), 'open-example', () => irA(fich.path)); | |
| 638 | + else p.appendChild(el('div', 'muted', tx('cHighlightTry', { exts: lista(f.highlight.flatMap(x => x.exts).slice(0, 4)) }))); | |
| 639 | + } | |
| 416 | 640 | } |
| 641 | + | |
| 642 | + for (const l of rec.languages || []) { | |
| 643 | + if (!l.configKey || host.builtinLanguage?.(l.id)) continue; | |
| 644 | + const que = resumenAjustes(await host.languageConfig(rec.id, l.id).catch(() => null)); | |
| 645 | + if (que.length) parte().appendChild(el('div', null, tx('cSettings', { lang: nombreLenguaje(l.id, [{ id: l.id, name: l.aliases?.[0] }]), what: lista(que) }))); | |
| 646 | + } | |
| 647 | + | |
| 648 | + if (f.snippets.length) { | |
| 649 | + const p = parte(); | |
| 650 | + const n = f.snippets.reduce((a, s) => a + (s.count || 0), 0); | |
| 651 | + p.appendChild(el('div', null, tx('cSnippets', { n, list: lista(f.snippets.map(s => s.name)) }))); | |
| 652 | + const prefijos = await host.snippetPrefixes(rec.id).catch(() => []); | |
| 653 | + if (prefijos.length) p.appendChild(el('div', null, tx('cSnippetsTry', { prefixes: listaO(prefijos.map(cita)) }))); | |
| 654 | + const destino = await ficheroCon(m, f.snippets.map(s => s.id)); | |
| 655 | + if (destino) boton(botones(p), tx('bTryIn', { file: baseName(destino.path) }), 'try-snippet', () => pruebaSnippets(rec, destino.path)); | |
| 656 | + } | |
| 657 | + | |
| 658 | + for (const l of v.lines) box.appendChild(el('div', 'ext-done-part ext-v-more', l)); | |
| 659 | + if (f.keepsBuiltin.length) box.appendChild(el('div', 'ext-done-part ext-v-more', tx('keepsBuiltin', { list: lista(f.keepsBuiltin) }))); | |
| 660 | + $('ext-done')?.remove(); | |
| 661 | + sitio.after(box); | |
| 662 | + // la región viva sigue anunciándolo; a la vista basta con la tarjeta | |
| 663 | + if (!sitio.classList.contains('err')) sitio.classList.add('ext-msg-sr'); | |
| 417 | 664 | } |
| 418 | 665 | |
| 419 | -// ── instaladas ── | |
| 420 | 666 | function claveFoco(x) { |
| 421 | 667 | const k = x?.closest?.('[data-k]')?.dataset.k; |
| 422 | 668 | const id = x?.closest?.('.ext-row')?.dataset.id; |
| @@ -430,6 +676,46 @@ | ||
| 430 | 676 | if (x) x.focus(); else $('ext-installed-h')?.focus(); |
| 431 | 677 | } |
| 432 | 678 | |
| 679 | +// Lo que esta extensión está haciendo AHORA, con un botón para verlo. | |
| 680 | +function lineasAhora(e, f) { | |
| 681 | + const box = el('div', 'ext-now'); | |
| 682 | + const linea = (texto, act = null, accesible = null, fn = null) => { | |
| 683 | + const d = el('div', 'ext-now-line', texto + ' '); | |
| 684 | + if (act) { | |
| 685 | + const b = el('button', 'ext-link', tx('bTry')); | |
| 686 | + b.type = 'button'; | |
| 687 | + b.dataset.act = act; | |
| 688 | + b.dataset.k = act; | |
| 689 | + if (accesible) b.setAttribute('aria-label', accesible); | |
| 690 | + b.onclick = fn; | |
| 691 | + d.appendChild(b); | |
| 692 | + } | |
| 693 | + box.appendChild(d); | |
| 694 | + }; | |
| 695 | + if (e.themes?.length) { | |
| 696 | + const activo = e.themes.find(t => t.themeId === host.currentTheme()); | |
| 697 | + linea(activo ? tx('nThemeActive', { name: activo.label }) : tx('nThemeIdle')); | |
| 698 | + } | |
| 699 | + if (f.highlight.length) { | |
| 700 | + const ids = f.highlight.map(x => x.id); | |
| 701 | + const abiertas = pestañasCon(ideCargado, ids); | |
| 702 | + const nombres = lista(f.highlight.map(x => x.name)); | |
| 703 | + linea(abiertas.length ? tx('nHighlighting', { n: abiertas.length, list: nombres }) | |
| 704 | + : tx('nHighlightIdle', { list: lista(f.highlight.map(x => x.name + (x.exts.length ? ` (${x.exts.slice(0, 3).join(', ')})` : ''))) }), | |
| 705 | + 'try-highlight', tx('tryHighlightNamed', { name: nombres }), () => pruebaResaltado(ids)); | |
| 706 | + } | |
| 707 | + if (f.settingsOnly.length) linea(tx('nSettings', { list: lista(f.settingsOnly) })); | |
| 708 | + if (f.snippets.length) { | |
| 709 | + const n = f.snippets.reduce((a, s) => a + (s.count || 0), 0); | |
| 710 | + const langs = lista(f.snippets.map(s => s.name)); | |
| 711 | + linea(tx('nSnippets', { n, list: langs }), 'try-snippet', tx('trySnippetsNamed', { name: e.displayName }), async () => { | |
| 712 | + const destino = await ficheroCon(await ide(), f.snippets.map(s => s.id)); | |
| 713 | + await pruebaSnippets(e, destino?.path); | |
| 714 | + }); | |
| 715 | + } | |
| 716 | + return box.childNodes.length ? box : null; | |
| 717 | +} | |
| 718 | + | |
| 433 | 719 | function pintaInstaladas() { |
| 434 | 720 | const box = $('ext-installed'); |
| 435 | 721 | if (!box) return; |
| @@ -452,15 +738,13 @@ | ||
| 452 | 738 | t.append(el('b', null, e.displayName), el('span', 'muted', ` ${e.id} · v${e.version}${e.enabled ? '' : ' · ' + tx('disabled')}`)); |
| 453 | 739 | main.append(t); |
| 454 | 740 | if (e.description) main.appendChild(el('div', 'ext-desc', e.description)); |
| 455 | - const r = resumen({ | |
| 456 | - themes: e.themes?.length || 0, | |
| 457 | - grammarLangs: (e.grammars || []).map(g => g.language ?? null), | |
| 458 | - languageList: (e.languages || []).map(l => ({ id: l.id, config: !!l.configKey })), | |
| 459 | - snippetLangs: [...new Set((e.snippets || []).map(s => s.language))], | |
| 460 | - ignored: e.ignored || [], hasCode: e.hasCode, pack: e.pack || [], | |
| 461 | - }); | |
| 462 | - for (const l of r.lineas) main.appendChild(el('div', l.cls, l.t)); | |
| 463 | - // lo que el paquete declaraba y no se pudo usar: plegado, sin esconderlo | |
| 741 | + const f = hechosDeRegistro(e); | |
| 742 | + const v = describe(f); | |
| 743 | + if (e.enabled && !host.paused) { | |
| 744 | + const ahora = lineasAhora(e, f); | |
| 745 | + if (ahora) main.appendChild(ahora); | |
| 746 | + } else main.appendChild(el('div', 'ext-now muted', tx('nOff'))); | |
| 747 | + main.appendChild(bloqueVeredicto(f, v, { principal: false })); | |
| 464 | 748 | const avisos = avisosVisibles(e.warnings).map(textoAviso).filter(Boolean); |
| 465 | 749 | if (avisos.length) { |
| 466 | 750 | const d = el('details', 'ext-warn'); |
added web/js/ext/verdict.js +121 −0
| @@ -0,0 +1,121 @@ | ||
| 1 | +// Lo que una extensión hará de verdad en Code, dicho en llano y en una línea, | |
| 2 | +// antes de instalarla y después. Nada de términos internos (los nombres de | |
| 3 | +// las contribuciones, «main/browser», «host de extensiones»): el usuario ve | |
| 4 | +// qué funciona, qué no, y si lo que no funciona llegará o no. | |
| 5 | +// | |
| 6 | +// Entrada: los «hechos» de una extensión (del package.json de Open VSX antes de | |
| 7 | +// instalar, o del registro ya instalado; panel.js los arma): | |
| 8 | +// hasCode, browserEntry, categories, sizes {clave de contribución: cuántas}, | |
| 9 | +// webviews, ignored [{key}], themes [nombre], highlight [{name, exts}], | |
| 10 | +// settingsOnly [nombre], snippets [{name, count|null}] | |
| 11 | +import { tx } from './i18n.js'; | |
| 12 | +import { uiLang } from '../i18n.js'; | |
| 13 | + | |
| 14 | +export function listaO(xs) { | |
| 15 | + const v = [...new Set(xs.filter(Boolean))]; | |
| 16 | + try { return new Intl.ListFormat(uiLang(), { type: 'disjunction' }).format(v); } catch { return v.join(', '); } | |
| 17 | +} | |
| 18 | +export function lista(xs) { | |
| 19 | + const v = [...new Set(xs.filter(Boolean))]; | |
| 20 | + try { return new Intl.ListFormat(uiLang(), { type: 'conjunction' }).format(v); } catch { return v.join(', '); } | |
| 21 | +} | |
| 22 | +export const esTexto = x => typeof x === 'string' && !!x.trim() && !/^%[^%\s]+%$/.test(x); | |
| 23 | +const corta = (xs, n = 4) => (xs.length > n ? [...xs.slice(0, n), tx('andMore', { n: xs.length - n })] : xs); | |
| 24 | + | |
| 25 | +// Categorías de Open VSX que hablan de una función que hace su código. | |
| 26 | +const POR_CATEGORIA = { | |
| 27 | + Formatters: 'fFormat', Linters: 'fLint', Debuggers: 'fDebug', Visualization: 'fPreview', Notebooks: 'fNotebooks', | |
| 28 | + Testing: 'fTesting', 'SCM Providers': 'fScm', 'Data Science': 'fData', 'Machine Learning': 'fAI', AI: 'fAI', Chat: 'fAI', | |
| 29 | + Keymaps: 'fKeys', Education: null, Other: null, Themes: null, Snippets: null, 'Programming Languages': null, 'Language Packs': 'fLangPack', | |
| 30 | + Azure: 'fCloud', 'Extension Packs': null, | |
| 31 | +}; | |
| 32 | +// Contribuciones que necesitan el código de la extensión, en palabras llanas. | |
| 33 | +const POR_CLAVE = { | |
| 34 | + commands: 'fCommands', menus: 'fCommands', submenus: 'fCommands', keybindings: 'fKeys', customEditors: 'fPreview', | |
| 35 | + views: 'fPanels', viewsContainers: 'fPanels', viewsWelcome: 'fPanels', debuggers: 'fDebug', breakpoints: 'fDebug', | |
| 36 | + taskDefinitions: 'fTasks', notebooks: 'fNotebooks', notebookRenderer: 'fNotebooks', configuration: 'fSettings', | |
| 37 | + jsonValidation: 'fJsonCheck', semanticTokenTypes: 'fSemantic', semanticTokenScopes: 'fSemantic', semanticTokenModifiers: 'fSemantic', | |
| 38 | + iconThemes: 'fIcons', productIconThemes: 'fIcons', terminal: 'fTerminal', chatParticipants: 'fAI', languageModelTools: 'fAI', | |
| 39 | + mcpServerDefinitionProviders: 'fAI', authentication: 'fAccounts', walkthroughs: 'fWalk', statusBarItems: 'fStatus', | |
| 40 | + codeActions: 'fCodeActions', typescriptServerPlugins: 'fLangServer', problemMatchers: 'fTasks', problemPatterns: 'fTasks', | |
| 41 | + resourceLabelFormatters: null, configurationDefaults: null, remoteHelp: null, colors: null, icons: 'fIcons', | |
| 42 | +}; | |
| 43 | +// Lo que ni con la siguiente versión funcionaría aquí: ventanas propias | |
| 44 | +// (vistas web, editores a medida), depuradores, terminales, cuadernos. | |
| 45 | +const NUNCA = new Set(['customEditors', 'notebookRenderer', 'notebooks', 'debuggers', 'terminal', 'views', 'viewsContainers']); | |
| 46 | +const DECLARATIVAS = new Set(['Themes', 'Snippets', 'Programming Languages']); | |
| 47 | + | |
| 48 | +// Funciones que no funcionan, en llano y sin repetir. | |
| 49 | +export function missingFeatures(f) { | |
| 50 | + const claves = []; | |
| 51 | + for (const c of f.categories || []) if (POR_CATEGORIA[c]) claves.push(POR_CATEGORIA[c]); | |
| 52 | + const principales = [...new Set(claves)]; | |
| 53 | + for (const i of f.ignored || []) { | |
| 54 | + const k = Object.hasOwn(POR_CLAVE, i.key) ? POR_CLAVE[i.key] : 'fOther'; | |
| 55 | + if (k) claves.push(k); | |
| 56 | + } | |
| 57 | + return { principales: principales.map(k => tx(k)), todas: [...new Set(claves)].map(k => tx(k)) }; | |
| 58 | +} | |
| 59 | + | |
| 60 | +// Lo principal que no funciona: lo que dicen sus categorías o, si no dicen | |
| 61 | +// nada, sus funciones concretas; «otras funciones» sola no explica nada. | |
| 62 | +function loPrincipal(principales, faltan) { | |
| 63 | + const concretas = faltan.filter(x => x !== tx('fOther')); | |
| 64 | + return lista((principales.length ? principales : concretas.length ? concretas : [tx('fOwn')]).slice(0, 3)); | |
| 65 | +} | |
| 66 | + | |
| 67 | +export function describe(f) { | |
| 68 | + const partes = []; // { tipo, texto } | |
| 69 | + const themes = f.themes || [], highlight = f.highlight || [], settingsOnly = f.settingsOnly || [], snippets = f.snippets || []; | |
| 70 | + // el package.json de Open VSX puede traer los nombres sin traducir (%clave%): | |
| 71 | + // entonces se cuentan en vez de nombrarlos | |
| 72 | + const conNombre = themes.filter(esTexto); | |
| 73 | + if (themes.length) partes.push({ tipo: 'theme', texto: conNombre.length === themes.length ? tx('pThemes', { n: themes.length, list: lista(corta(themes.map(t => tx('quoted', { x: t })))) }) : tx('pThemesCount', { n: themes.length }) }); | |
| 74 | + if (highlight.length) partes.push({ tipo: 'highlight', texto: tx('pHighlight', { list: lista(corta(highlight.map(h => h.name))) }) }); | |
| 75 | + if (settingsOnly.length) partes.push({ tipo: 'settings', texto: tx('pSettings', { list: lista(corta(settingsOnly)) }) }); | |
| 76 | + if (snippets.length) { | |
| 77 | + const total = snippets.every(s => Number.isFinite(s.count)) ? snippets.reduce((a, s) => a + s.count, 0) : null; | |
| 78 | + const langs = lista(corta([...new Set(snippets.map(s => s.name))])); | |
| 79 | + partes.push({ tipo: 'snippets', texto: total != null ? tx('pSnippetsN', { n: total, list: langs }) : tx('pSnippets', { list: langs }) }); | |
| 80 | + } | |
| 81 | + const usable = partes.length > 0; | |
| 82 | + const hasCode = !!f.hasCode; | |
| 83 | + const sizes = f.sizes || {}; | |
| 84 | + const nunca = !!f.webviews || Object.keys(sizes).some(k => NUNCA.has(k)); | |
| 85 | + const { principales, todas } = missingFeatures(f); | |
| 86 | + const faltan = hasCode && !todas.length ? [tx('fOwn')] : todas; | |
| 87 | + // ¿lo principal es lo que hace su código? Si no se declara como tema, | |
| 88 | + // snippets o lenguaje; si trae ventanas propias; o si casi todo son comandos | |
| 89 | + const categorias = f.categories || []; | |
| 90 | + const codigoManda = hasCode && (!usable || !categorias.some(c => DECLARATIVAS.has(c)) || nunca || (sizes.commands || 0) >= 10); | |
| 91 | + const futuro = !hasCode ? null : f.browserEntry && !nunca ? 'next' : 'never'; | |
| 92 | + const queTraen = lista(partes.map(p => p.texto)); | |
| 93 | + const lineas = []; | |
| 94 | + let kind, verdict; | |
| 95 | + if (!usable) { | |
| 96 | + kind = hasCode ? 'code' : 'nothing'; | |
| 97 | + if (hasCode) { | |
| 98 | + verdict = tx('vMainBroken', { what: loPrincipal(principales, faltan) }); | |
| 99 | + lineas.push(tx(futuro === 'next' ? 'vNextVersion' : 'vNever')); | |
| 100 | + } else verdict = tx('nothing'); | |
| 101 | + } else if (!hasCode && !faltan.length) { | |
| 102 | + kind = 'full'; | |
| 103 | + verdict = tx('vFull', { list: queTraen }); | |
| 104 | + } else if (codigoManda) { | |
| 105 | + kind = 'mostlyCode'; | |
| 106 | + verdict = tx('vMainBroken', { what: loPrincipal(principales, faltan) }); | |
| 107 | + lineas.push(tx('vOnly', { list: queTraen })); | |
| 108 | + lineas.push(tx(futuro === 'next' ? 'vNextVersion' : 'vNever')); | |
| 109 | + } else { | |
| 110 | + kind = 'partial'; | |
| 111 | + verdict = tx('vPartial', { list: queTraen }); | |
| 112 | + lineas.push(tx(!hasCode ? 'vMissingLater' : futuro === 'next' ? 'vMissingNext' : 'vMissingNever', { list: lista(faltan) })); | |
| 113 | + } | |
| 114 | + const tipos = [...new Set(partes.map(p => p.tipo === 'settings' ? 'highlight' : p.tipo))]; | |
| 115 | + const soloQue = tipos.length === 1 ? { theme: 'installOnlyThemes', highlight: 'installOnlyHighlight', snippets: 'installOnlySnippets' }[tipos[0]] : 'installOnlyWorking'; | |
| 116 | + const button = kind === 'full' ? { key: 'install', style: 'primary', disabled: false } | |
| 117 | + : kind === 'partial' ? { key: soloQue, style: 'primary', disabled: false } | |
| 118 | + : kind === 'mostlyCode' ? { key: soloQue, style: 'ghost', disabled: false } | |
| 119 | + : { key: kind === 'code' ? 'notHere' : 'nothingHere', style: 'ghost', disabled: true }; | |
| 120 | + return { kind, verdict, lines: lineas, button, future: futuro, usable, missing: faltan, parts: partes }; | |
| 121 | +} |
modified web/js/ext/vsix.js +16 −2
| @@ -39,8 +39,22 @@ | ||
| 39 | 39 | // para decir qué NO se aplicaría aunque se instale (panel.js): el lenguaje |
| 40 | 40 | // de cada gramática y si cada lenguaje trae configuración |
| 41 | 41 | const grammarLangs = arr('grammars').map(g => (typeof g?.language === 'string' ? g.language : null)); |
| 42 | - const languageList = arr('languages').filter(l => typeof l?.id === 'string' && l.id).map(l => ({ id: l.id, config: typeof l.configuration === 'string' })); | |
| 43 | - return { applies, ignored, hasCode, pack, snippetLangs, languages, grammarLangs, languageList, any: Object.values(applies).some(Boolean) }; | |
| 42 | + const languageList = arr('languages').filter(l => typeof l?.id === 'string' && l.id).map(l => ({ | |
| 43 | + id: l.id, config: typeof l.configuration === 'string', | |
| 44 | + name: Array.isArray(l.aliases) && typeof l.aliases[0] === 'string' ? l.aliases[0] : undefined, | |
| 45 | + extensions: Array.isArray(l.extensions) ? l.extensions.filter(x => typeof x === 'string') : [], | |
| 46 | + })); | |
| 47 | + // para el veredicto en lenguaje llano (verdict.js): de qué va, qué partes | |
| 48 | + // necesitan su código y si ese código podría correr en un navegador | |
| 49 | + const categories = Array.isArray(pkg?.categories) ? pkg.categories.filter(x => typeof x === 'string') : []; | |
| 50 | + const sizes = {}; | |
| 51 | + for (const k of Object.keys(c)) sizes[k] = Array.isArray(c[k]) ? c[k].length : c[k] && typeof c[k] === 'object' ? Object.keys(c[k]).length : 1; | |
| 52 | + const webviews = Object.values(c.views && typeof c.views === 'object' ? c.views : {}).some(v => Array.isArray(v) && v.some(x => x?.type === 'webview')); | |
| 53 | + const themeLabels = arr('themes').map(t => (typeof t?.label === 'string' ? t.label : typeof t?.id === 'string' ? t.id : null)).filter(Boolean); | |
| 54 | + return { | |
| 55 | + applies, ignored, hasCode, pack, snippetLangs, languages, grammarLangs, languageList, any: Object.values(applies).some(Boolean), | |
| 56 | + categories, sizes, webviews, browserEntry: typeof pkg?.browser === 'string', themeLabels, | |
| 57 | + }; | |
| 44 | 58 | } |
| 45 | 59 | |
| 46 | 60 | // %clave% → texto de package.nls(.<idioma>).json, en todo el manifiesto. |
modified web/js/ide.js +6 −0
| @@ -86,6 +86,12 @@ | ||
| 86 | 86 | // La ruta del fichero activo (o null): el menú la usa para no lanzar acciones |
| 87 | 87 | // del editor que no hacen nada sin un fichero abierto. |
| 88 | 88 | export function activeFile() { return active; } |
| 89 | +// Las pestañas abiertas y su lenguaje, y el lenguaje que tendría una ruta: el | |
| 90 | +// panel de extensiones los usa para decir qué ficheros ya se ven distintos. | |
| 91 | +export function openTabs() { | |
| 92 | + return tabs.filter(t => !t.model.isDisposed()).map(t => ({ path: t.path, language: t.model.getLanguageId(), active: t.path === active })); | |
| 93 | +} | |
| 94 | +export const languageOfPath = p => langOf(p); | |
| 89 | 95 | |
| 90 | 96 | export async function openFile(path) { |
| 91 | 97 | let tab = tabs.find(t => t.path === path); |