Skip to content

Commit

Permalink
Merge pull request #224 from prettyv/omnisharp-integration-fix
Browse files Browse the repository at this point in the history
Fix integration with Omnisharp solution selection when it's not currently active
  • Loading branch information
fernandoescolar authored Oct 10, 2022
2 parents 8fcac2e + 4ac2661 commit d5e8b6a
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/OmnisharpIntegrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { IEventAggregator, SolutionSelected } from "@events";

interface BaseEvent {
type: number;
solutionPath?: string;
}

interface OmnisharpInitialisationEvent extends BaseEvent {
dotNetCliPaths: string[];
timeStamp: Date;
solutionPath: string;
}

interface Subscription {
Expand All @@ -30,22 +35,18 @@ export class OmnisharpIntegrationService extends vscode.Disposable {

public register() {
this.active = config.getOpenSolutionsSelectedInOmnisharp();
if (!this.active) { return; }

const checker = setInterval(() => {
const extension = vscode.extensions.getExtension(CSHARP_EXTENSION_ID) as any;
if (!extension) {
clearInterval(checker);
}
if (!this.active) {
return;
}

if (extension.exports) {
const extension = vscode.extensions.getExtension(CSHARP_EXTENSION_ID);
if (extension) {
if (extension.isActive && extension.exports) {
this.start(extension);
clearInterval(checker);
} else {
extension.activate().then(() => this.start(extension));
clearInterval(checker);
}
}, 0);
}
}

public unregister(): void {
Expand All @@ -66,8 +67,9 @@ export class OmnisharpIntegrationService extends vscode.Disposable {

private handleEvent(event: BaseEvent): void {
if (event.type === SELECT_SOLUTION_EVENT_TYPE) {
if (event.solutionPath && event.solutionPath.toLocaleLowerCase().endsWith(SOLUTION_EXTENSION)) {
const e = new SolutionSelected(event.solutionPath);
const solutionPath = (event as OmnisharpInitialisationEvent).solutionPath;
if (solutionPath.toLocaleLowerCase().endsWith(SOLUTION_EXTENSION)) {
const e = new SolutionSelected(solutionPath);
this.eventAggregator.publish(e);
}
}
Expand Down

0 comments on commit d5e8b6a

Please sign in to comment.