Skip to content

Commit f3bfe80

Browse files
authored
Merge pull request #5096 from Tyriar/tyriar/esbuild4
Integrate base/ platform from VS Code and adopt scroll bar
2 parents 995ccc7 + 90a1da2 commit f3bfe80

File tree

97 files changed

+19838
-601
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+19838
-601
lines changed

.eslintrc.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"src/browser/tsconfig.json",
1212
"src/common/tsconfig.json",
1313
"src/headless/tsconfig.json",
14+
"src/vs/tsconfig.json",
1415
"test/benchmark/tsconfig.json",
1516
"test/playwright/tsconfig.json",
1617
"addons/addon-attach/src/tsconfig.json",
@@ -43,6 +44,7 @@
4344
},
4445
"ignorePatterns": [
4546
"addons/*/src/third-party/*.ts",
47+
"src/vs/*",
4648
"out/*",
4749
"out-test/*",
4850
"out-esbuild/*",

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
},
55
// Hide output files from the file explorer, comment this out to see the build output
66
"files.exclude": {
7+
"**/.nyc_output": true,
78
"**/lib": true,
9+
"**/dist": true,
810
"**/out": true,
911
"**/out-*": true,
1012
},

addons/addon-fit/src/FitAddon.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import type { Terminal, ITerminalAddon } from '@xterm/xterm';
77
import type { FitAddon as IFitApi } from '@xterm/addon-fit';
88
import { IRenderDimensions } from 'browser/renderer/shared/Types';
9+
import { ViewportConstants } from 'browser/shared/Constants';
910

1011
interface ITerminalDimensions {
1112
/**
@@ -64,8 +65,9 @@ export class FitAddon implements ITerminalAddon , IFitApi {
6465
return undefined;
6566
}
6667

67-
const scrollbarWidth = this._terminal.options.scrollback === 0 ?
68-
0 : core.viewport.scrollBarWidth;
68+
const scrollbarWidth = (this._terminal.options.scrollback === 0
69+
? 0
70+
: (this._terminal.options.overviewRulerWidth || ViewportConstants.DEFAULT_SCROLL_BAR_WIDTH));
6971

7072
const parentElementStyle = window.getComputedStyle(this._terminal.element.parentElement);
7173
const parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height'));

bin/esbuild.mjs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ const config = {
2020

2121
/** @type {esbuild.BuildOptions} */
2222
const commonOptions = {
23+
bundle: true,
2324
format: 'esm',
2425
target: 'es2021',
2526
sourcemap: true,
27+
treeShaking: true,
2628
logLevel: 'debug',
2729
};
2830

@@ -34,8 +36,6 @@ const devOptions = {
3436
/** @type {esbuild.BuildOptions} */
3537
const prodOptions = {
3638
minify: true,
37-
treeShaking: true,
38-
logLevel: 'debug',
3939
legalComments: 'none',
4040
// TODO: Mangling private and protected properties will reduce bundle size quite a bit, we must
4141
// make sure we don't cast privates to `any` in order to prevent regressions.
@@ -80,20 +80,21 @@ function getAddonEntryPoint(addon) {
8080

8181
/** @type {esbuild.BuildOptions} */
8282
let bundleConfig = {
83-
bundle: true,
8483
...commonOptions,
8584
...(config.isProd ? prodOptions : devOptions)
8685
};
8786

8887
/** @type {esbuild.BuildOptions} */
8988
let outConfig = {
90-
format: 'cjs'
89+
format: 'cjs',
90+
sourcemap: true,
9191
}
9292
let skipOut = false;
9393

9494
/** @type {esbuild.BuildOptions} */
9595
let outTestConfig = {
96-
format: 'cjs'
96+
format: 'cjs',
97+
sourcemap: true,
9798
}
9899
let skipOutTest = false;
99100

@@ -171,7 +172,13 @@ if (config.addon) {
171172
};
172173
outConfig = {
173174
...outConfig,
174-
entryPoints: ['src/**/*.ts'],
175+
entryPoints: [
176+
'src/browser/**/*.ts',
177+
'src/common/**/*.ts',
178+
'src/headless/**/*.ts',
179+
'src/vs/base/**/*.ts',
180+
'src/vs/patches/**/*.ts'
181+
],
175182
outdir: 'out-esbuild/'
176183
};
177184
outTestConfig = {

bin/test_unit.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ const checkCoverage = flagArgs.indexOf('--coverage') >= 0;
3434
if (checkCoverage) {
3535
flagArgs.splice(flagArgs.indexOf('--coverage'), 1);
3636
const executable = npmBinScript('nyc');
37-
const args = ['--check-coverage', `--lines=${COVERAGE_LINES_THRESHOLD}`, npmBinScript('mocha'), ...testFiles, ...flagArgs];
37+
const args = [
38+
'--check-coverage',
39+
`--lines=${COVERAGE_LINES_THRESHOLD}`,
40+
'--exclude=out-esbuild/vs/**',
41+
npmBinScript('mocha'),
42+
...testFiles,
43+
...flagArgs
44+
];
3845
console.info('executable', executable);
3946
console.info('args', args);
4047
const run = cp.spawnSync(

bin/vs_base_find_unused.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// @ts-check
2+
3+
const { dirname } = require("path");
4+
const ts = require("typescript");
5+
const fs = require("fs");
6+
7+
function findUnusedSymbols(
8+
/** @type string */ tsconfigPath
9+
) {
10+
// Initialize a program using the project's tsconfig.json
11+
const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
12+
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, dirname(tsconfigPath));
13+
14+
// Initialize a program with the parsed configuration
15+
const program = ts.createProgram(parsedConfig.fileNames, {
16+
...parsedConfig.options,
17+
noUnusedLocals: true
18+
});
19+
const sourceFiles = program.getSourceFiles();
20+
const usedBaseSourceFiles = sourceFiles.filter(e => e.fileName.includes('src/vs/base/'));
21+
const usedFilesInBase = usedBaseSourceFiles.map(e => e.fileName.replace(/^.+\/src\//, 'src/')).sort((a, b) => a.localeCompare(b));
22+
// console.log('Source files used in src/vs/base/:', used);
23+
24+
// Get an array of all files that exist in src/vs/base/
25+
const allFilesInBase = (
26+
fs.readdirSync('src/vs/base', { recursive: true, withFileTypes: true })
27+
.filter(e => e.isFile())
28+
// @ts-ignore HACK: This is only available in Node 20
29+
.map(e => `${e.parentPath}/${e.name}`.replace(/\\/g, '/'))
30+
);
31+
const unusedFilesInBase = allFilesInBase.filter(e => !usedFilesInBase.includes(e));
32+
33+
console.log({
34+
allFilesInBase,
35+
usedFilesInBase,
36+
unusedFilesInBase
37+
});
38+
}
39+
40+
// Example usage
41+
findUnusedSymbols("./src/browser/tsconfig.json");

bin/vs_base_update.ps1

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Get latest vscode repo
2+
if (Test-Path -Path "src/vs/temp") {
3+
Write-Host "`e[32m> Fetching latest`e[0m"
4+
git -C src/vs/temp checkout
5+
git -C src/vs/temp pull
6+
} else {
7+
Write-Host "`e[32m> Cloning microsoft/vscode`e[0m"
8+
$null = New-Item -ItemType Directory -Path "src/vs/temp" -Force
9+
git clone https://github.com/microsoft/vscode src/vs/temp
10+
}
11+
12+
# Delete old base
13+
Write-Host "`e[32m> Deleting old base`e[0m"
14+
$null = Remove-Item -Recurse -Force "src/vs/base"
15+
16+
# Copy base
17+
Write-Host "`e[32m> Copying base`e[0m"
18+
Copy-Item -Path "src/vs/temp/src/vs/base" -Destination "src/vs/base" -Recurse
19+
20+
# Comment out any CSS imports
21+
Write-Host "`e[32m> Commenting out CSS imports" -NoNewline
22+
$baseFiles = Get-ChildItem -Path "src/vs/base" -Recurse -File
23+
$count = 0
24+
foreach ($file in $baseFiles) {
25+
$content = Get-Content -Path $file.FullName
26+
$updatedContent = $content | ForEach-Object {
27+
if ($_ -match "^import 'vs/css!") {
28+
Write-Host "`e[32m." -NoNewline
29+
$count++
30+
"// $_"
31+
} else {
32+
$_
33+
}
34+
}
35+
$updatedContent | Set-Content -Path $file.FullName
36+
}
37+
Write-Host " $count files patched`e[0m"
38+
39+
# Replace `monaco-*` with `xterm-*`, this will help avoid any styling conflicts when monaco and
40+
# xterm.js are used in the same project.
41+
Write-Host "`e[32m> Replacing monaco-* class names with xterm-* `e[0m" -NoNewline
42+
$baseFiles = Get-ChildItem -Path "src/vs/base" -Recurse -File
43+
$count = 0
44+
foreach ($file in $baseFiles) {
45+
$content = Get-Content -Path $file.FullName
46+
if ($content -match "monaco-([a-zA-Z\-]+)") {
47+
$updatedContent = $content -replace "monaco-([a-zA-Z\-]+)", 'xterm-$1'
48+
Write-Host "`e[32m." -NoNewline
49+
$count++
50+
$updatedContent | Set-Content -Path $file.FullName
51+
}
52+
}
53+
Write-Host " $count files patched`e[0m"
54+
55+
# Copy typings
56+
Write-Host "`e[32m> Copying typings`e[0m"
57+
Copy-Item -Path "src/vs/temp/src/typings" -Destination "src/vs" -Recurse -Force
58+
59+
# Deleting unwanted typings
60+
Write-Host "`e[32m> Deleting unwanted typings`e[0m"
61+
$null = Remove-Item -Path "src/vs/typings/vscode-globals-modules.d.ts" -Force

css/xterm.css

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@
112112
top: 0;
113113
}
114114

115-
.xterm .xterm-scroll-area {
116-
visibility: hidden;
117-
}
118-
119115
.xterm-char-measure-element {
120116
display: inline-block;
121117
visibility: hidden;
@@ -222,3 +218,68 @@
222218
z-index: 2;
223219
position: relative;
224220
}
221+
222+
223+
224+
/* Derived from vs/base/browser/ui/scrollbar/media/scrollbar.css */
225+
226+
/* xterm.js customization: Override xterm's cursor style */
227+
.xterm .xterm-scrollable-element > .scrollbar {
228+
cursor: default;
229+
}
230+
231+
/* Arrows */
232+
.xterm .xterm-scrollable-element > .scrollbar > .scra {
233+
cursor: pointer;
234+
font-size: 11px !important;
235+
}
236+
237+
.xterm .xterm-scrollable-element > .visible {
238+
opacity: 1;
239+
240+
/* Background rule added for IE9 - to allow clicks on dom node */
241+
background:rgba(0,0,0,0);
242+
243+
transition: opacity 100ms linear;
244+
/* In front of peek view */
245+
z-index: 11;
246+
}
247+
.xterm .xterm-scrollable-element > .invisible {
248+
opacity: 0;
249+
pointer-events: none;
250+
}
251+
.xterm .xterm-scrollable-element > .invisible.fade {
252+
transition: opacity 800ms linear;
253+
}
254+
255+
/* Scrollable Content Inset Shadow */
256+
.xterm .xterm-scrollable-element > .shadow {
257+
position: absolute;
258+
display: none;
259+
}
260+
.xterm .xterm-scrollable-element > .shadow.top {
261+
display: block;
262+
top: 0;
263+
left: 3px;
264+
height: 3px;
265+
width: 100%;
266+
box-shadow: var(--vscode-scrollbar-shadow, #000) 0 6px 6px -6px inset;
267+
}
268+
.xterm .xterm-scrollable-element > .shadow.left {
269+
display: block;
270+
top: 3px;
271+
left: 0;
272+
height: 100%;
273+
width: 3px;
274+
box-shadow: var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset;
275+
}
276+
.xterm .xterm-scrollable-element > .shadow.top-left-corner {
277+
display: block;
278+
top: 0;
279+
left: 0;
280+
height: 3px;
281+
width: 3px;
282+
}
283+
.xterm .xterm-scrollable-element > .shadow.top.left {
284+
box-shadow: var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset;
285+
}

demo/client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,13 @@ function initOptions(term: Terminal): void {
437437
'logger',
438438
'theme',
439439
'windowOptions',
440-
'windowsPty'
440+
'windowsPty',
441+
// Deprecated
442+
'fastScrollModifier'
441443
];
442444
const stringOptions = {
443445
cursorStyle: ['block', 'underline', 'bar'],
444446
cursorInactiveStyle: ['outline', 'block', 'bar', 'underline', 'none'],
445-
fastScrollModifier: ['none', 'alt', 'ctrl', 'shift'],
446447
fontFamily: null,
447448
fontWeight: ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'],
448449
fontWeightBold: ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'],
@@ -575,6 +576,7 @@ function initOptions(term: Terminal): void {
575576
cursor: '#333333',
576577
cursorAccent: '#ffffff',
577578
selectionBackground: '#add6ff',
579+
overviewRulerBorder: '#aaaaaa',
578580
black: '#000000',
579581
blue: '#0451a5',
580582
brightBlack: '#666666',

demo/webpack.config.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)