Skip to content

Commit

Permalink
Merge branch 'master' into fix-encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
a1994846931931 authored Jun 14, 2019
2 parents 2617a37 + f1c23e2 commit 888d018
Show file tree
Hide file tree
Showing 12 changed files with 317 additions and 21 deletions.
6 changes: 3 additions & 3 deletions packages/debug/src/node/debug-adapter-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ export class DebugAdapterSessionImpl implements DebugAdapterSession {
this.channel.onClose(() => this.channel = undefined);

this.communicationProvider.output.on('data', (data: Buffer) => this.handleData(data));
this.communicationProvider.output.on('close', () => this.fireExited());
this.communicationProvider.output.on('close', () => this.onDebugAdapterExit(1, undefined)); // FIXME pass a proper exit code
this.communicationProvider.output.on('error', error => this.onDebugAdapterError(error));
this.communicationProvider.input.on('error', error => this.onDebugAdapterError(error));
}

protected fireExited(): void {
protected onDebugAdapterExit(exitCode: number, signal: string | undefined): void {
const event: DebugProtocol.ExitedEvent = {
type: 'event',
event: 'exited',
seq: -1,
body: {
exitCode: 1 // FIXME pass a proper exit code
exitCode
}
};
this.send(JSON.stringify(event));
Expand Down
3 changes: 3 additions & 0 deletions packages/editor/src/browser/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ export interface TextEditor extends Disposable, TextEditorSelection, IEncodingSu

readonly onMouseDown: Event<EditorMouseEvent>;

readonly onScrollChanged: Event<void>;
getVisibleRanges(): Range[];

revealPosition(position: Position, options?: RevealPositionOptions): void;
revealRange(range: Range, options?: RevealRangeOptions): void;

Expand Down
48 changes: 46 additions & 2 deletions packages/keymaps/src/browser/keybindings-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,23 @@ export class KeybindingWidget extends ReactWidget {
// Match identical keybindings that have different orders
if (key === 'keybinding') {
const queryItems = this.query.split('+');
const bindingItems = string.split('+');

// Handle key chords
const tempItems = string.split(' ');
// Store positions of `space` in the keybinding string
const spaceIndexArr = [0];
let bindingItems: string[] = [];
if (tempItems.length > 1) {
tempItems.forEach(tItem => {
const tKeys = tItem.split('+');
spaceIndexArr.push(tKeys.length + spaceIndexArr[-1]);
bindingItems.push(...tKeys);
});
} else {
bindingItems = string.split('+');
}
spaceIndexArr.shift();

const renderedResult = [...bindingItems];
let matchCounter = 0;

Expand All @@ -137,12 +153,27 @@ export class KeybindingWidget extends ReactWidget {
renderedResult[keyIndex] = keyRendered;
}
// Remove key from keybinding items if it is matched
bindingItems.splice(keyIndex, 1);
bindingItems.splice(keyIndex, 1, '');
matchCounter += 1;
}
}
});
if (matchCounter === queryItems.length) {
// Handle rendering of key chords
if (spaceIndexArr.length > 0) {
const chordRenderedResult = '';
renderedResult.forEach((resultKey, index) => {
if (index === 0) {
chordRenderedResult.concat(resultKey);
} else if (spaceIndexArr.indexOf(index) !== -1) {
chordRenderedResult.concat(' ' + resultKey);
} else {
chordRenderedResult.concat('+' + resultKey);
}
});
item[key] = chordRenderedResult;
}

item[key] = renderedResult.join('+');
matched = true;
}
Expand Down Expand Up @@ -265,6 +296,19 @@ export class KeybindingWidget extends ReactWidget {
return <span key={index} className='monaco-keybinding-key'>
{this.renderMatchedData(key)}
</span>;
} else if (key.includes(' ')) {
// Handle key chords, which have space as the separator
// Example: `k Ctrl` in key chords `Ctrl+k Ctrl+p`
let chordKeys = key.split('<match> </match>');
if (chordKeys.length === 1) {
chordKeys = key.split(' ');
}
return <React.Fragment key={index}>
<span className='monaco-keybinding-separator'>+</span>
<span className='monaco-keybinding-key'>{this.renderKeybinding(chordKeys[0])}</span>
<span className='monaco-keybinding-separator'>&nbsp;&nbsp;</span>
<span className='monaco-keybinding-key'>{this.renderKeybinding(chordKeys[1])}</span>
</React.Fragment>;
} else {
return <React.Fragment key={index}>
<span className='monaco-keybinding-separator'>+</span>
Expand Down
2 changes: 1 addition & 1 deletion packages/keymaps/src/browser/keymaps-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class KeymapsService {

@postConstruct()
protected async init() {
this.resource = await this.resourceProvider(new URI('keymaps.json').withScheme(UserStorageUri.SCHEME));
this.resource = await this.resourceProvider(new URI().withScheme(UserStorageUri.SCHEME).withPath('keymaps.json'));
this.reconcile();
if (this.resource.onDidChangeContents) {
this.resource.onDidChangeContents(() => this.reconcile());
Expand Down
15 changes: 14 additions & 1 deletion packages/monaco/src/browser/monaco-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class MonacoEditor implements TextEditor {
readonly onLanguageChanged = this.onLanguageChangedEmitter.event;
protected readonly onEncodingChangedEmitter = new Emitter<string>();
readonly onEncodingChanged = this.onEncodingChangedEmitter.event;
protected readonly onScrollChangedEmitter = new Emitter<void>();

readonly documents = new Set<MonacoEditorModel>();

Expand All @@ -84,7 +85,8 @@ export class MonacoEditor implements TextEditor {
this.onDocumentContentChangedEmitter,
this.onMouseDownEmitter,
this.onLanguageChangedEmitter,
this.onEncodingChangedEmitter
this.onEncodingChangedEmitter,
this.onScrollChangedEmitter
]);
this.documents.add(document);
this.autoSizing = options && options.autoSizing !== undefined ? options.autoSizing : false;
Expand Down Expand Up @@ -159,6 +161,13 @@ export class MonacoEditor implements TextEditor {
event: e.event.browserEvent
});
}));
this.toDispose.push(codeEditor.onDidScrollChange(e => {
this.onScrollChangedEmitter.fire(undefined);
}));
}

getVisibleRanges(): Range[] {
return this.editor.getVisibleRanges().map(range => this.m2p.asRange(range));
}

protected mapModelContentChange(change: monaco.editor.IModelContentChange): TextDocumentContentChangeDelta {
Expand Down Expand Up @@ -204,6 +213,10 @@ export class MonacoEditor implements TextEditor {
return this.onSelectionChangedEmitter.event;
}

get onScrollChanged(): Event<void> {
return this.onScrollChangedEmitter.event;
}

revealPosition(raw: Position, options: RevealPositionOptions = { vertical: 'center' }): void {
const position = this.p2m.asPosition(raw);
switch (options.vertical) {
Expand Down
19 changes: 19 additions & 0 deletions packages/plugin-ext/src/plugin/node/debug/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { startDebugAdapter, connectDebugAdapter } from './plugin-debug-adapter-s
import { resolveDebugAdapterExecutable } from './plugin-debug-adapter-executable-resolver';
import URI from 'vscode-uri';
import { Path } from '@theia/core/lib/common/path';
import { PluginDebugAdapterTracker } from './plugin-debug-adapter-tracker';

// tslint:disable:no-any

Expand All @@ -51,6 +52,7 @@ export class DebugExtImpl implements DebugExt {
// providers by type
private configurationProviders = new Map<string, Set<theia.DebugConfigurationProvider>>();
private debuggersContributions = new Map<string, DebuggerContribution>();
private trackerFactories: [string, theia.DebugAdapterTrackerFactory][] = [];
private contributionPaths = new Map<string, string>();

private connectionExt: ConnectionExtImpl;
Expand Down Expand Up @@ -133,6 +135,17 @@ export class DebugExtImpl implements DebugExt {
return this.proxy.$startDebugging(folder, nameOrConfiguration);
}

registerDebugAdapterTrackerFactory(debugType: string, factory: theia.DebugAdapterTrackerFactory): Disposable {
if (!factory) {
return Disposable.create(() => { });
}

this.trackerFactories.push([debugType, factory]);
return Disposable.create(() => {
this.trackerFactories = this.trackerFactories.filter(tuple => tuple[1] !== factory);
});
}

registerDebugConfigurationProvider(debugType: string, provider: theia.DebugConfigurationProvider): Disposable {
console.log(`Debug configuration provider has been registered: ${debugType}`);
const providers = this.configurationProviders.get(debugType) || new Set<theia.DebugConfigurationProvider>();
Expand Down Expand Up @@ -199,6 +212,7 @@ export class DebugExtImpl implements DebugExt {
(command: string, args?: any) => this.proxy.$customRequest(sessionId, command, args));
this.sessions.set(sessionId, debugAdapterSession);

await this.configureTracker(debugAdapterSession);
const connection = await this.connectionExt!.ensureConnection(sessionId);
debugAdapterSession.start(new PluginWebSocketChannel(connection));

Expand Down Expand Up @@ -275,6 +289,11 @@ export class DebugExtImpl implements DebugExt {
return current;
}

protected async configureTracker(session: PluginDebugAdapterSession): Promise<void> {
const tracker = await PluginDebugAdapterTracker.create(session, this.trackerFactories);
session.configureTracker(tracker);
}

private async getExecutable(debugConfiguration: theia.DebugConfiguration): Promise<DebugAdapterExecutable> {
const { type } = debugConfiguration;
const contribution = this.debuggersContributions.get(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import * as theia from '@theia/plugin';
import { CommunicationProvider } from '@theia/debug/lib/common/debug-model';
import { DebugAdapterSessionImpl } from '@theia/debug/lib/node/debug-adapter-session';
import * as theia from '@theia/plugin';
import { DebugProtocol } from 'vscode-debugprotocol';
import { IWebSocket } from 'vscode-ws-jsonrpc/lib/socket/socket';

// tslint:disable
// tslint:disable: no-any

/**
* Server debug adapter session.
Expand All @@ -28,6 +29,8 @@ export class PluginDebugAdapterSession extends DebugAdapterSessionImpl implement
readonly type: string;
readonly name: string;

protected tracker: theia.DebugAdapterTracker | undefined;

constructor(
readonly id: string,
readonly configuration: theia.DebugConfiguration,
Expand All @@ -39,4 +42,53 @@ export class PluginDebugAdapterSession extends DebugAdapterSessionImpl implement
this.type = configuration.type;
this.name = configuration.name;
}

async start(channel: IWebSocket): Promise<void> {
if (this.tracker && this.tracker.onWillStartSession) {
this.tracker.onWillStartSession();
}
await super.start(channel);
}

async stop(): Promise<void> {
if (this.tracker && this.tracker.onWillStopSession) {
this.tracker.onWillStopSession();
}
await super.stop();
}

configureTracker(tracker: theia.DebugAdapterTracker) {
this.tracker = tracker;
}

protected onDebugAdapterError(error: Error): void {
if (this.tracker && this.tracker.onError) {
this.tracker.onError(error);
}
super.onDebugAdapterError(error);
}

protected send(message: string): void {
try {
super.send(message);
} finally {
if (this.tracker && this.tracker.onDidSendMessage) {
this.tracker.onDidSendMessage(message);
}
}
}

protected write(message: string): void {
if (this.tracker && this.tracker.onWillReceiveMessage) {
this.tracker.onWillReceiveMessage(message);
}
super.write(message);
}

protected onDebugAdapterExit(exitCode: number, signal: string | undefined): void {
if (this.tracker && this.tracker.onExit) {
this.tracker.onExit(exitCode, signal);
}
super.onDebugAdapterExit(exitCode, signal);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/********************************************************************************
* Copyright (C) 2019 Red Hat, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

// tslint:disable: no-any

import * as theia from '@theia/plugin';

export class PluginDebugAdapterTracker implements theia.DebugAdapterTracker {
constructor(protected readonly trackers: theia.DebugAdapterTracker[]) { }

static async create(session: theia.DebugSession, trackerFactories: [string, theia.DebugAdapterTrackerFactory][]): Promise<PluginDebugAdapterTracker> {
const trackers: theia.DebugAdapterTracker[] = [];

const factories = trackerFactories.filter(tuple => tuple[0] === '*' || tuple[0] === session.type).map(tuple => tuple[1]);
for (const factory of factories) {
const tracker = await factory.createDebugAdapterTracker(session);
if (tracker) {
trackers.push(tracker);
}
}

return new PluginDebugAdapterTracker(trackers);
}

onWillStartSession(): void {
this.trackers.forEach(tracker => {
if (tracker.onWillStartSession) {
tracker.onWillStartSession();
}
});
}

onWillReceiveMessage(message: any): void {
this.trackers.forEach(tracker => {
if (tracker.onWillReceiveMessage) {
tracker.onWillReceiveMessage(message);
}
});
}

onDidSendMessage(message: any): void {
this.trackers.forEach(tracker => {
if (tracker.onDidSendMessage) {
tracker.onDidSendMessage(message);
}
});
}

onWillStopSession(): void {
this.trackers.forEach(tracker => {
if (tracker.onWillStopSession) {
tracker.onWillStopSession();
}
});
}

onError(error: Error): void {
this.trackers.forEach(tracker => {
if (tracker.onError) {
tracker.onError(error);
}
});
}

onExit(code: number | undefined, signal: string | undefined): void {
this.trackers.forEach(tracker => {
if (tracker.onExit) {
tracker.onExit(code, signal);
}
});
}
}
Loading

0 comments on commit 888d018

Please sign in to comment.