Skip to content

Commit

Permalink
Merge pull request #337 from che-incubator/resolve_conflicts
Browse files Browse the repository at this point in the history
chore: Rebase against upstream
  • Loading branch information
RomanNikitenko committed Mar 18, 2024
2 parents 34da54a + 458194e commit 4c59d22
Show file tree
Hide file tree
Showing 57 changed files with 450 additions and 182 deletions.
14 changes: 14 additions & 0 deletions .rebase/CHANGELOG.md
Expand Up @@ -20,3 +20,17 @@ https://github.com/che-incubator/che-code/pull/326

- code/product.json
---

#### @benoitf @RomanNikitenko
https://github.com/che-incubator/che-code/pull/43/commits/d04ac87e51e09d3f2328efb2bdcdcd23a259b969 \
https://github.com/che-incubator/che-code/pull/337/commits/875893566c2acd0bb7031ac3db9d7002ca36feb1#diff-bf304bf7a29dbc8f1d0cbb3219344cd3aeb6d8262394731c63bc40326a8760ce

- code/src/vs/base/common/network.ts
---


#### @benoitf
https://github.com/che-incubator/che-code/commit/eed0a5213ba1b29b810d53f6365aaa2294165845#diff-2735bf66f14ee64b9ce6fdc30355a5e3085ae96a791cd01d65843a8dcef7c166

- code/src/vs/server/webClientServer.ts
---
7 changes: 2 additions & 5 deletions code/cli/src/commands/tunnels.rs
Expand Up @@ -50,10 +50,7 @@ use crate::{
AuthRequired, Next, ServeStreamParams, ServiceContainer, ServiceManager,
},
util::{
app_lock::AppMutex,
command::new_std_command,
errors::{wrap, AnyError, CodeError},
prereqs::PreReqChecker,
app_lock::AppMutex, command::new_std_command, errors::{wrap, AnyError, CodeError}, machine::canonical_exe, prereqs::PreReqChecker
},
};
use crate::{
Expand Down Expand Up @@ -231,7 +228,7 @@ pub async fn service(
legal::require_consent(&ctx.paths, args.accept_server_license_terms)?;

let current_exe =
std::env::current_exe().map_err(|e| wrap(e, "could not get current exe"))?;
canonical_exe().map_err(|e| wrap(e, "could not get current exe"))?;

manager
.register(
Expand Down
81 changes: 80 additions & 1 deletion code/cli/src/util/machine.rs
Expand Up @@ -3,7 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

use std::{path::Path, time::Duration};
use std::{
ffi::OsString,
path::{Path, PathBuf},
time::Duration,
};
use sysinfo::{Pid, PidExt, ProcessExt, System, SystemExt};

pub fn process_at_path_exists(pid: u32, name: &Path) -> bool {
Expand Down Expand Up @@ -71,3 +75,78 @@ pub async fn wait_until_exe_deleted(current_exe: &Path, poll_ms: u64) {
tokio::time::sleep(duration).await;
}
}

/// Gets the canonical current exe location, referring to the "current" symlink
/// if running inside snap.
pub fn canonical_exe() -> std::io::Result<PathBuf> {
canonical_exe_inner(
std::env::current_exe(),
std::env::var_os("SNAP"),
std::env::var_os("SNAP_REVISION"),
)
}

#[inline(always)]
#[allow(unused_variables)]
fn canonical_exe_inner(
exe: std::io::Result<PathBuf>,
snap: Option<OsString>,
rev: Option<OsString>,
) -> std::io::Result<PathBuf> {
let exe = exe?;

#[cfg(target_os = "linux")]
if let (Some(snap), Some(rev)) = (snap, rev) {
if !exe.starts_with(snap) {
return Ok(exe);
}

let mut out = PathBuf::new();
for part in exe.iter() {
if part == rev {
out.push("current")
} else {
out.push(part)
}
}

return Ok(out);
}

Ok(exe)
}

#[cfg(test)]
mod tests {
use super::*;
use std::path::PathBuf;

#[test]
#[cfg(target_os = "linux")]
fn test_canonical_exe_in_snap() {
let exe = canonical_exe_inner(
Ok(PathBuf::from("/snap/my-snap/1234/some/exe")),
Some("/snap/my-snap/1234".into()),
Some("1234".into()),
)
.unwrap();
assert_eq!(exe, PathBuf::from("/snap/my-snap/current/some/exe"));
}

#[test]
fn test_canonical_exe_not_in_snap() {
let exe = canonical_exe_inner(
Ok(PathBuf::from("/not-in-snap")),
Some("/snap/my-snap/1234".into()),
Some("1234".into()),
)
.unwrap();
assert_eq!(exe, PathBuf::from("/not-in-snap"));
}

#[test]
fn test_canonical_exe_not_in_snap2() {
let exe = canonical_exe_inner(Ok(PathBuf::from("/not-in-snap")), None, None).unwrap();
assert_eq!(exe, PathBuf::from("/not-in-snap"));
}
}
2 changes: 1 addition & 1 deletion code/extensions/ruby/language-configuration.json
Expand Up @@ -26,6 +26,6 @@
],
"indentationRules": {
"increaseIndentPattern": "^\\s*((begin|class|(private|protected)\\s+def|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|in|while|case)|([^#]*\\sdo\\b)|([^#]*=\\s*(case|if|unless)))\\b([^#\\{;]|(\"|'|\/).*\\4)*(#.*)?$",
"decreaseIndentPattern": "^\\s*([}\\]]([,)]?\\s*(#|$)|\\.[a-zA-Z_]\\w*\\b)|(end|rescue|ensure|else|elsif)\\b)|((in|when)\\s)"
"decreaseIndentPattern": "^\\s*([}\\]]([,)]?\\s*(#|$)|\\.[a-zA-Z_]\\w*\\b)|(end|rescue|ensure|else|elsif)\\b|(in|when)\\s)"
}
}
16 changes: 12 additions & 4 deletions code/src/vs/base/common/network.ts
Expand Up @@ -7,6 +7,7 @@ import * as errors from 'vs/base/common/errors';
import * as platform from 'vs/base/common/platform';
import { equalsIgnoreCase, startsWithIgnoreCase } from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
import * as paths from 'vs/base/common/path';

export namespace Schemas {

Expand Down Expand Up @@ -144,7 +145,7 @@ class RemoteAuthoritiesImpl {
private readonly _connectionTokens: { [authority: string]: string | undefined } = Object.create(null);
private _preferredWebSchema: 'http' | 'https' = 'http';
private _delegate: ((uri: URI) => URI) | null = null;
// private _remoteResourcesPath: string = `/${Schemas.vscodeRemoteResource}`;
private _serverRootPath: string = '/';

setPreferredWebSchema(schema: 'http' | 'https') {
this._preferredWebSchema = schema;
Expand All @@ -154,8 +155,12 @@ class RemoteAuthoritiesImpl {
this._delegate = delegate;
}

setServerRootPath(serverRootPath: string): void {
// this._remoteResourcesPath = `${serverRootPath}/${Schemas.vscodeRemoteResource}`;
setServerRootPath(product: { quality?: string; commit?: string }, serverBasePath: string | undefined): void {
this._serverRootPath = getServerRootPath(product, serverBasePath);
}

getServerRootPath(): string {
return this._serverRootPath;
}

set(authority: string, host: string, port: number): void {
Expand Down Expand Up @@ -191,7 +196,6 @@ class RemoteAuthoritiesImpl {
if (typeof connectionToken === 'string') {
query += `&${connectionTokenQueryName}=${encodeURIComponent(connectionToken)}`;
}

return URI.from({
scheme: platform.isWeb ? this._preferredWebSchema : Schemas.vscodeRemoteResource,
authority: `${host}:${port}`,
Expand All @@ -203,6 +207,10 @@ class RemoteAuthoritiesImpl {

export const RemoteAuthorities = new RemoteAuthoritiesImpl();

export function getServerRootPath(product: { quality?: string; commit?: string }, basePath: string | undefined): string {
return paths.posix.join(basePath ?? '/', `${product.quality ?? 'oss'}-${product.commit ?? 'dev'}`);
}

/**
* A string pointing to a path inside the app. It should not begin with ./ or ../
*/
Expand Down
Expand Up @@ -331,10 +331,7 @@ export class HoverWidget extends Widget implements IHoverWidget {
};

const targetBounds = this._target.targetElements.map(e => getZoomAccountedBoundingClientRect(e));
const top = Math.min(...targetBounds.map(e => e.top));
const right = Math.max(...targetBounds.map(e => e.right));
const bottom = Math.max(...targetBounds.map(e => e.bottom));
const left = Math.min(...targetBounds.map(e => e.left));
const { top, right, bottom, left } = targetBounds[0];
const width = right - left;
const height = bottom - top;

Expand Down
Expand Up @@ -56,13 +56,20 @@ export class CopyPasteController extends Disposable implements IEditorContributi
return editor.getContribution<CopyPasteController>(CopyPasteController.ID);
}

private readonly _editor: ICodeEditor;

private _currentCopyOperation?: {
/**
* Global tracking the last copy operation.
*
* This is shared across all editors so that you can copy and paste between groups.
*
* TODO: figure out how to make this work with multiple windows
*/
private static _currentCopyOperation?: {
readonly handle: string;
readonly dataTransferPromise: CancelablePromise<VSDataTransfer>;
};

private readonly _editor: ICodeEditor;

private _currentPasteOperation?: CancelablePromise<void>;
private _pasteAsActionContext?: { readonly preferredId: string | undefined };

Expand Down Expand Up @@ -204,8 +211,8 @@ export class CopyPasteController extends Disposable implements IEditorContributi
return dataTransfer;
});

this._currentCopyOperation?.dataTransferPromise.cancel();
this._currentCopyOperation = { handle: handle, dataTransferPromise: promise };
CopyPasteController._currentCopyOperation?.dataTransferPromise.cancel();
CopyPasteController._currentCopyOperation = { handle: handle, dataTransferPromise: promise };
}

private async handlePaste(e: ClipboardEvent) {
Expand Down Expand Up @@ -436,8 +443,8 @@ export class CopyPasteController extends Disposable implements IEditorContributi
}

private async mergeInDataFromCopy(dataTransfer: VSDataTransfer, metadata: CopyMetadata | undefined, token: CancellationToken): Promise<void> {
if (metadata?.id && this._currentCopyOperation?.handle === metadata.id) {
const toMergeDataTransfer = await this._currentCopyOperation.dataTransferPromise;
if (metadata?.id && CopyPasteController._currentCopyOperation?.handle === metadata.id) {
const toMergeDataTransfer = await CopyPasteController._currentCopyOperation.dataTransferPromise;
if (token.isCancellationRequested) {
return;
}
Expand Down
Expand Up @@ -373,16 +373,23 @@ suite('Editor Contrib - Auto Dedent On Type', () => {
['(', ')']
],
indentationRules: {
decreaseIndentPattern: /\s*([}\]]([,)]?\s*(#|$)|\.[a-zA-Z_]\w*\b)|(end|rescue|ensure|else|elsif)\b)|((in|when)\s)/,
decreaseIndentPattern: /^\s*([}\]]([,)]?\s*(#|$)|\.[a-zA-Z_]\w*\b)|(end|rescue|ensure|else|elsif)\b|(in|when)\s)/,
increaseIndentPattern: /^\s*((begin|class|(private|protected)\s+def|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|in|while|case)|([^#]*\sdo\b)|([^#]*=\s*(case|if|unless)))\b([^#\{;]|(\"|'|\/).*\4)*(#.*)?$/,
},
});

viewModel.model.setValue("");
viewModel.type("def foo\n i");
viewModel.type("n", 'keyboard');
assert.strictEqual(model.getValue(), "def foo\n in");
viewModel.type(" ", 'keyboard');
assert.strictEqual(model.getValue(), "def foo\nin ");

viewModel.model.setValue("");
viewModel.type(" # in");
assert.strictEqual(model.getValue(), " # in");
viewModel.type(" ", 'keyboard');
assert.strictEqual(model.getValue(), " # in ");
improvedLanguageModel.dispose();
});
});
Expand Down
Expand Up @@ -515,7 +515,6 @@ class CandidatesView {
public layout({ height, width }: { height: number; width: number }): void {
this._availableHeight = height;
this._minimumWidth = width;
this._listContainer.style.width = `${this._minimumWidth}px`;
}

public setCandidates(candidates: NewSymbolName[]): void {
Expand Down
19 changes: 14 additions & 5 deletions code/src/vs/platform/actions/browser/buttonbar.ts
Expand Up @@ -4,6 +4,8 @@
*--------------------------------------------------------------------------------------------*/

import { ButtonBar, IButton } from 'vs/base/browser/ui/button/button';
import { getDefaultHoverDelegate } from 'vs/base/browser/ui/hover/hoverDelegate';
import { setupCustomHover } from 'vs/base/browser/ui/iconLabel/iconLabelHover';
import { ActionRunner, IAction, IActionRunner, SubmenuAction, WorkbenchActionExecutedClassification, WorkbenchActionExecutedEvent } from 'vs/base/common/actions';
import { Emitter, Event } from 'vs/base/common/event';
import { DisposableStore } from 'vs/base/common/lifecycle';
Expand All @@ -29,6 +31,7 @@ export interface IWorkbenchButtonBarOptions {
export class WorkbenchButtonBar extends ButtonBar {

protected readonly _store = new DisposableStore();
protected readonly _updateStore = new DisposableStore();

private readonly _actionRunner: IActionRunner;
private readonly _onDidChange = new Emitter<this>();
Expand Down Expand Up @@ -57,6 +60,7 @@ export class WorkbenchButtonBar extends ButtonBar {

override dispose() {
this._onDidChange.dispose();
this._updateStore.dispose();
this._store.dispose();
super.dispose();
}
Expand All @@ -65,8 +69,12 @@ export class WorkbenchButtonBar extends ButtonBar {

const conifgProvider: IButtonConfigProvider = this._options?.buttonConfigProvider ?? (() => ({ showLabel: true }));

this._updateStore.clear();
this.clear();

// Support instamt hover between buttons
const hoverDelegate = this._updateStore.add(getDefaultHoverDelegate('element', true));

for (let i = 0; i < actions.length; i++) {

const secondary = i > 0;
Expand Down Expand Up @@ -107,15 +115,16 @@ export class WorkbenchButtonBar extends ButtonBar {
}
}
const kb = this._keybindingService.lookupKeybinding(action.id);
let tooltip: string;
if (kb) {
btn.element.title = localize('labelWithKeybinding', "{0} ({1})", action.label, kb.getLabel());
tooltip = localize('labelWithKeybinding', "{0} ({1})", action.label, kb.getLabel());
} else {
btn.element.title = action.label;

tooltip = action.label;
}
btn.onDidClick(async () => {
this._updateStore.add(setupCustomHover(hoverDelegate, btn.element, tooltip));
this._updateStore.add(btn.onDidClick(async () => {
this._actionRunner.run(action);
});
}));
}
this._onDidChange.fire(this);
}
Expand Down
Expand Up @@ -17,10 +17,9 @@ import { IStorageService } from 'vs/platform/storage/common/storage';
import { TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
import { getTelemetryLevel, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
import { RemoteAuthorities } from 'vs/base/common/network';
import { getRemoteServerRootPath } from 'vs/platform/remote/common/remoteHosts';
import { TargetPlatform } from 'vs/platform/extensions/common/extensions';

const WEB_EXTENSION_RESOURCE_END_POINT = 'web-extension-resource';
const WEB_EXTENSION_RESOURCE_END_POINT_SEGMENT = '/web-extension-resource/';

export const IExtensionResourceLoaderService = createDecorator<IExtensionResourceLoaderService>('extensionResourceLoaderService');

Expand Down Expand Up @@ -67,7 +66,6 @@ export abstract class AbstractExtensionResourceLoaderService implements IExtensi

readonly _serviceBrand: undefined;

private readonly _webExtensionResourceEndPoint: string;
private readonly _extensionGalleryResourceUrlTemplate: string | undefined;
private readonly _extensionGalleryAuthority: string | undefined;

Expand All @@ -78,7 +76,6 @@ export abstract class AbstractExtensionResourceLoaderService implements IExtensi
private readonly _environmentService: IEnvironmentService,
private readonly _configurationService: IConfigurationService,
) {
this._webExtensionResourceEndPoint = `${getRemoteServerRootPath(_productService)}/${WEB_EXTENSION_RESOURCE_END_POINT}/`;
if (_productService.extensionsGallery) {
this._extensionGalleryResourceUrlTemplate = _productService.extensionsGallery.resourceUrlTemplate;
this._extensionGalleryAuthority = this._extensionGalleryResourceUrlTemplate ? this._getExtensionGalleryAuthority(URI.parse(this._extensionGalleryResourceUrlTemplate)) : undefined;
Expand Down Expand Up @@ -144,7 +141,9 @@ export abstract class AbstractExtensionResourceLoaderService implements IExtensi
}

protected _isWebExtensionResourceEndPoint(uri: URI): boolean {
return uri.path.startsWith(this._webExtensionResourceEndPoint);
const uriPath = uri.path, serverRootPath = RemoteAuthorities.getServerRootPath();
// test if the path starts with the server root path followed by the web extension resource end point segment
return uriPath.startsWith(serverRootPath) && uriPath.startsWith(WEB_EXTENSION_RESOURCE_END_POINT_SEGMENT, serverRootPath.length);
}

}

0 comments on commit 4c59d22

Please sign in to comment.