Skip to content

Commit

Permalink
10011: Fix asDebugSourceUri
Browse files Browse the repository at this point in the history
- Rename asDebugSourceURI to getDebugSourceUri to avoid name clash
- Fix the way the debug source query is built
- Add tests

Contributed on behalf of STMicroelectronics

Signed-off-by: Camille Letavernier <[email protected]>
  • Loading branch information
CamilleLetavernier committed May 5, 2022
1 parent ace2159 commit d75ba90
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 5 deletions.
93 changes: 93 additions & 0 deletions packages/plugin-ext/src/plugin/node/debug/debug.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// *****************************************************************************
// Copyright (C) 2021 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
// *****************************************************************************

import { DebugSession } from '@theia/plugin';
import * as chai from 'chai';
import { ProxyIdentifier, RPCProtocol } from '../../../common/rpc-protocol';

import { DebugExtImpl } from './debug';

const expect = chai.expect;

describe('Debug source URI:', () => {

const mockRPCProtocol: RPCProtocol = {
getProxy<T>(_proxyId: ProxyIdentifier<T>): T {
return {} as T;
},
set<T, R extends T>(_id: ProxyIdentifier<T>, instance: R): R {
return instance;
},
dispose(): void {
// Nothing
}
};

const debug = new DebugExtImpl(mockRPCProtocol);

it('Should use sourceReference, path and sessionId', () => {
const source = {
sourceReference: 3,
path: 'test/path'
};
const session = { id: 'test-session' } as DebugSession;
const uri = debug.asDebugSourceUri(source, session);
expect(uri.toString(true)).to.be.equal('debug:test/path?ref=3&session=test-session');
});

it('should use sourceReference', () => {
const source = {
sourceReference: 5
};
const uri = debug.asDebugSourceUri(source);
expect(uri.toString(true)).to.be.equal('debug:?ref=5');
});

it('should use sourceReference and session', () => {
const source = {
sourceReference: 5
};
const session = { id: 'test-session' } as DebugSession;
const uri = debug.asDebugSourceUri(source, session);
expect(uri.toString(true)).to.be.equal('debug:?ref=5&session=test-session');
});

it('should use sourceReference and path', () => {
const source = {
sourceReference: 4,
path: 'test/path'
};
const uri = debug.asDebugSourceUri(source);
expect(uri.toString(true)).to.be.equal('debug:test/path?ref=4');
});

it('should use path', () => {
const source = {
path: 'scheme:/full/path'
};
const uri = debug.asDebugSourceUri(source);
expect(uri.toString(true)).to.be.equal('scheme:/full/path');
});

it('should use file path', () => {
const source = {
path: '/full/path'
};
const uri = debug.asDebugSourceUri(source);
expect(uri.toString(true)).to.be.equal('file:///full/path');
});

});
10 changes: 5 additions & 5 deletions packages/plugin-ext/src/plugin/node/debug/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,17 @@ export class DebugExtImpl implements DebugExt {
static SCHEME_PATTERN = /^[a-zA-Z][a-zA-Z0-9\+\-\.]+:/;
asDebugSourceUri(source: theia.DebugProtocolSource, session?: theia.DebugSession): theia.Uri {
const raw = source as DebugProtocol.Source;
const uri = this.asDebugSourceURI(raw, session?.id);
const uri = this.getDebugSourceUri(raw, session?.id);
return URIImpl.parse(uri.toString());
}

private asDebugSourceURI(raw: DebugProtocol.Source, sessionId?: string): TheiaURI {
private getDebugSourceUri(raw: DebugProtocol.Source, sessionId?: string): TheiaURI {
if (raw.sourceReference && raw.sourceReference > 0) {
let query = String(raw.sourceReference);
let query = 'ref=' + String(raw.sourceReference);
if (sessionId) {
query += `?session=${sessionId}`;
query += `&session=${sessionId}`;
}
return new TheiaURI().withScheme(DebugExtImpl.SCHEME).withPath(raw.name!).withQuery(query);
return new TheiaURI().withScheme(DebugExtImpl.SCHEME).withPath(raw.path || '').withQuery(query);
}
if (!raw.path) {
throw new Error('Unrecognized source type: ' + JSON.stringify(raw));
Expand Down

0 comments on commit d75ba90

Please sign in to comment.