Skip to content

Commit

Permalink
Merge pull request #128 from CodinGame/various-improvements
Browse files Browse the repository at this point in the history
Various improvements and fixes
  • Loading branch information
CGNonofr authored Jun 16, 2023
2 parents 962e0bc + 56c4005 commit f82fbfd
Show file tree
Hide file tree
Showing 20 changed files with 313 additions and 191 deletions.
2 changes: 1 addition & 1 deletion demo/src/features/terminal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import getTerminalServiceOverride, { ITerminalChildProcess, SimpleTerminalBackend, SimpleTerminalProcess } from 'vscode/service-override/terminal'
import { ITerminalChildProcess, SimpleTerminalBackend, SimpleTerminalProcess } from 'vscode/service-override/terminal'
import ansiColors from 'ansi-colors'
import * as vscode from 'vscode'

Expand Down
1 change: 1 addition & 0 deletions demo/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import 'vscode/default-extensions/typescript-basics'
import 'vscode/default-extensions/json'
import 'vscode/default-extensions/theme-seti'
import 'vscode/default-extensions/references-view'
import 'vscode/default-extensions/search-result'

const modelRef = await createModelReference(monaco.Uri.file('/tmp/test.js'), `// import anotherfile
let variable = 1
Expand Down
5 changes: 4 additions & 1 deletion demo/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ window.MonacoEnvironment = {
return new Worker()
}
throw new Error(`Unimplemented worker ${label} (${moduleId})`)
},
createTrustedTypesPolicy () {
return undefined
}
}

Expand All @@ -72,7 +75,7 @@ await initializeMonacoService({
...getSearchAccessServiceOverride(),
...getMarkersAccessServiceOverride()
})
StandaloneServices.get(ILogService).setLevel(LogLevel.Off)
StandaloneServices.get(ILogService).setLevel(LogLevel.Error)

await initializeVscodeExtensions()

Expand Down
2 changes: 1 addition & 1 deletion demo/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default defineConfig({
'vscode/service-override/preferences', 'vscode/service-override/snippets', 'vscode/service-override/files', 'vscode/service-override/output',
'vscode/service-override/terminal', 'vscode/service-override/search', 'vscode/service-override/markers',
'vscode/default-extensions/theme-defaults', 'vscode/default-extensions/javascript', 'vscode/default-extensions/json', 'vscode/default-extensions/theme-seti',
'vscode/default-extensions/references-view', 'vscode/default-extensions/typescript-basics'
'vscode/default-extensions/references-view', 'vscode/default-extensions/typescript-basics', 'vscode/default-extensions/search-result'
]
},
server: {
Expand Down
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"@octokit/rest": "^19.0.11",
"@rollup/plugin-commonjs": "^25.0.1",
"@rollup/plugin-dynamic-import-vars": "^2.0.3",
"@rollup/plugin-inject": "^5.0.3",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-replace": "^5.0.2",
Expand Down Expand Up @@ -301,11 +302,11 @@
"vscode-textmate": "^9.0.0",
"xterm": "5.2.1",
"xterm-addon-canvas": "0.4.0",
"xterm-addon-image": "0.4.1",
"xterm-addon-search": "0.12.0",
"xterm-addon-serialize": "0.10.0",
"xterm-addon-unicode11": "0.5.0",
"xterm-addon-webgl": "0.15.0",
"xterm-addon-image": "0.4.1",
"yauzl": "^2.10.0"
},
"overrides": {
Expand Down
18 changes: 15 additions & 3 deletions rollup/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import externalAssets from 'rollup-plugin-external-assets'
import globImport from 'rollup-plugin-glob-import'
import terser from '@rollup/plugin-terser'
import styles from 'rollup-plugin-styles'
import inject from '@rollup/plugin-inject'
import * as fs from 'fs'
import * as path from 'path'
import { fileURLToPath } from 'url'
Expand Down Expand Up @@ -63,8 +64,6 @@ const FUNCTIONS_TO_REMOVE = new Set([
'registerProxyConfigurations',
'registerViewWelcomeContent',
'registerExtensionPoint',
'_setExtensionHostProxy',
'_setAllMainProxyIdentifiers',
'registerTouchBarEntry',
'registerEditorSerializer',

Expand Down Expand Up @@ -126,6 +125,13 @@ function isCallPure (file: string, functionName: string, node: recast.types.name
return true
}

if (functionName === 'createInstance') {
const firstParam = args[0]!
if (firstParam.type === 'Identifier' && firstParam.name === 'ExtHostConsoleForwarder') {
return true
}
}

if (functionName === 'KeybindingsRegistry.registerCommandAndKeybindingRule') {
const firstParam = args[0]!
if (firstParam.type === 'ObjectExpression') {
Expand Down Expand Up @@ -331,6 +337,7 @@ const USE_DEFAULT_EXTENSIONS = new Set([
'ruby',
'rust',
'scss',
'search-result',
'shaderlab',
'shellscript',
'sql',
Expand Down Expand Up @@ -430,7 +437,8 @@ export default (args: Record<string, string>): rollup.RollupOptions[] => {
id.endsWith('/listCommands.js') ||
id.endsWith('/quickAccessActions.js') ||
id.endsWith('/gotoLineQuickAccess.js') ||
id.endsWith('/workbenchReferenceSearch.js')
id.endsWith('/workbenchReferenceSearch.js') ||
id.includes('/searchActions')
}
},
external,
Expand All @@ -450,6 +458,10 @@ export default (args: Record<string, string>): rollup.RollupOptions[] => {
}],
input,
plugins: [
inject({
fetch: path.resolve('src/custom-fetch.ts'),
include: [/extHostExtensionService/]
}),
commonjs(),
extensionDirectoryPlugin({
include: `${DEFAULT_EXTENSIONS_PATH}/**/*`,
Expand Down
21 changes: 17 additions & 4 deletions scripts/vscode.patch
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ index fc197da1d57..a4d9573979f 100644
public static validateOptions(options: IEditorOptions): ValidatedEditorOptions {
const result = new ValidatedEditorOptions();
diff --git a/src/vs/workbench/api/browser/statusBarExtensionPoint.ts b/src/vs/workbench/api/browser/statusBarExtensionPoint.ts
index 2ba47f8425e..8a004d610a4 100644
index 55e5013c812..1e7d271a466 100644
--- a/src/vs/workbench/api/browser/statusBarExtensionPoint.ts
+++ b/src/vs/workbench/api/browser/statusBarExtensionPoint.ts
@@ -51,7 +51,7 @@ export interface IExtensionStatusBarItemService {
@@ -49,7 +49,7 @@ export interface IExtensionStatusBarItemService {
}


Expand All @@ -160,10 +160,10 @@ index 2ba47f8425e..8a004d610a4 100644
declare readonly _serviceBrand: undefined;

diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts
index 07f2364ffed..04b61d8b808 100644
index 6dabdb4f4df..e48cd4f2828 100644
--- a/src/vs/workbench/api/common/extHostTerminalService.ts
+++ b/src/vs/workbench/api/common/extHostTerminalService.ts
@@ -816,15 +816,12 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
@@ -812,15 +812,12 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
}

private _getTerminalObjectIndexById<T extends ExtHostTerminal>(array: T[], id: ExtHostTerminalIdentifier): number | null {
Expand All @@ -184,6 +184,19 @@ index 07f2364ffed..04b61d8b808 100644
return index;
}

diff --git a/src/vs/workbench/browser/parts/compositeBar.ts b/src/vs/workbench/browser/parts/compositeBar.ts
index 36694129764..2920195c027 100644
--- a/src/vs/workbench/browser/parts/compositeBar.ts
+++ b/src/vs/workbench/browser/parts/compositeBar.ts
@@ -504,7 +504,7 @@ export class CompositeBar extends Widget implements ICompositeBar {
// Compute sizes only if visible. Otherwise the size measurment would be computed wrongly.
const currentItemsLength = compositeSwitcherBar.viewItems.length;
compositeSwitcherBar.push(items.map(composite => composite.activityAction));
- items.map((composite, index) => this.compositeSizeInBar.set(composite.id, this.options.orientation === ActionsOrientation.VERTICAL
+ items.forEach((composite, index) => this.compositeSizeInBar.set(composite.id, this.options.orientation === ActionsOrientation.VERTICAL
? compositeSwitcherBar.getHeight(currentItemsLength + index)
: compositeSwitcherBar.getWidth(currentItemsLength + index)
));
diff --git a/src/vs/workbench/browser/parts/views/viewPaneContainer.ts b/src/vs/workbench/browser/parts/views/viewPaneContainer.ts
index ff766b9acb8..599bab9dd59 100644
--- a/src/vs/workbench/browser/parts/views/viewPaneContainer.ts
Expand Down
26 changes: 26 additions & 0 deletions src/createApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type * as vscode from 'vscode'
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
import * as api from './api'
import createL10nApi from './vscode-services/l10n'
import createLanguagesApi from './vscode-services/languages'
import createCommandsApi from './vscode-services/commands'
import createWorkspaceApi from './vscode-services/workspace'
import createWindowApi from './vscode-services/window'
import createEnvApi from './vscode-services/env'
import createDebugApi from './vscode-services/debug'
import createExtensionsApi from './vscode-services/extensions'

export default function createApi (extension: IExtensionDescription): typeof vscode {
const workspace = createWorkspaceApi(() => extension)
return {
...api,
extensions: createExtensionsApi(() => extension),
debug: createDebugApi(() => extension),
env: createEnvApi(() => extension),
commands: createCommandsApi(() => extension),
window: createWindowApi(() => extension, workspace),
workspace: createWorkspaceApi(() => extension),
languages: createLanguagesApi(() => extension),
l10n: createL10nApi(() => extension)
}
}
37 changes: 37 additions & 0 deletions src/custom-fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { IFileService } from 'vs/platform/files/common/files'
import { StandaloneServices } from 'vs/editor/standalone/browser/standaloneServices'
import { URI } from 'vs/base/common/uri'
import { unsupported } from './tools'

const fetch: typeof window.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {
if (typeof input === 'string') {
const uri = URI.parse(input)
const fileService = StandaloneServices.get(IFileService)
if (fileService.hasProvider(uri)) {
const response: Response = {
get headers () { return unsupported() },
ok: true,
redirected: false,
status: 200,
statusText: 'Ok',
type: 'basic',
url: input,
clone: unsupported,
get body () { return unsupported() },
bodyUsed: false,
arrayBuffer: unsupported,
blob: unsupported,
formData: unsupported,
json: unsupported,
text: async function (): Promise<string> {
const content = await fileService.readFile(URI.parse(input))
return content.value.toString()
}
}
return response
}
}
return window.fetch(input, init)
}

export default fetch
22 changes: 20 additions & 2 deletions src/extension-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ParseError, parse } from 'vs/base/common/json.js'
import { getParseErrorMessage } from 'vs/base/common/jsonErrorMessages'
import { InputPluginOption, rollup } from 'rollup'
import { addExtension } from '@rollup/pluginutils'
import { IUserFriendlyViewsContainerDescriptor } from 'vs/workbench/api/browser/viewsExtensionPoint'
import * as path from 'path'

export interface ExtensionResource {
Expand Down Expand Up @@ -58,6 +59,7 @@ interface RealContribute {
themes?: IThemeExtensionPoint[]
iconThemes?: IThemeExtensionPoint[]
productIconThemes?: IThemeExtensionPoint[]
viewsContainers?: { [loc: string]: IUserFriendlyViewsContainerDescriptor[] }
}

function extractCommandResources (command: IUserFriendlyCommand | IUserFriendlyCommand[]): ExtensionResource[] {
Expand All @@ -81,10 +83,10 @@ function extractGrammarResources (grammar: ITMSyntaxExtensionPoint): ExtensionRe
function extractLanguageResources (language: Partial<IRawLanguageExtensionPoint>): ExtensionResource[] {
const paths: ExtensionResource[] = []
if (language.icon != null) {
paths.push({ path: language.icon.dark, sync: false }, { path: language.icon.light, sync: false })
paths.push({ path: language.icon.dark, sync: true }, { path: language.icon.light, sync: true })
}
if (language.configuration != null) {
paths.push({ path: language.configuration, sync: false })
paths.push({ path: language.configuration, sync: true })
}
return paths
}
Expand Down Expand Up @@ -127,6 +129,20 @@ async function extractThemeResources (theme: IThemeExtensionPoint, getFileConten
return paths
}

function extractJsonValidationResources (jsonValidation: IJSONValidationExtensionPoint): ExtensionResource[] {
return [{
path: jsonValidation.url,
sync: true
}]
}

function extractViewsContainerResources (viewContainers: { [loc: string]: IUserFriendlyViewsContainerDescriptor[] }): ExtensionResource[] {
return Object.values(viewContainers).flatMap(containers => containers.map(container => ({
path: container.icon,
sync: true
})))
}

async function extractResourcesFromExtensionManifestContribute (contribute: RealContribute, getFileContent: (path: string) => Promise<Buffer>): Promise<ExtensionResource[]> {
const resources: ExtensionResource[] = []
if (contribute.commands != null) resources.push(...extractCommandResources(contribute.commands))
Expand All @@ -136,6 +152,8 @@ async function extractResourcesFromExtensionManifestContribute (contribute: Real
if (contribute.themes != null) resources.push(...((await Promise.all(contribute.themes.map(theme => extractThemeResources(theme, getFileContent), getFileContent))).flat()))
if (contribute.iconThemes != null) resources.push(...((await Promise.all(contribute.iconThemes.map(theme => extractThemeResources(theme, getFileContent), getFileContent))).flat()))
if (contribute.productIconThemes != null) resources.push(...((await Promise.all(contribute.productIconThemes.map(theme => extractThemeResources(theme, getFileContent), getFileContent))).flat()))
if (contribute.jsonValidation != null) resources.push(...contribute.jsonValidation.flatMap(extractJsonValidationResources))
if (contribute.viewsContainers != null) resources.push(...extractViewsContainerResources(contribute.viewsContainers))
return resources.filter((resource, index, list) => !resource.path.startsWith('$(') && !list.slice(0, index).some(o => o.path === resource.path))
}

Expand Down
Loading

0 comments on commit f82fbfd

Please sign in to comment.