-
Notifications
You must be signed in to change notification settings - Fork 684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display prompt [Information Message] to restart the server when the omnisharp configuration changes #2316
Merged
Merged
Display prompt [Information Message] to restart the server when the omnisharp configuration changes #2316
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { Options } from "../omnisharp/options"; | ||
import { vscode } from "../vscodeAdapter"; | ||
import 'rxjs/add/operator/take'; | ||
import 'rxjs/add/operator/publishBehavior'; | ||
import { Observable } from "rxjs/Observable"; | ||
import { Observer } from "rxjs/Observer"; | ||
|
||
export default function createOptionStream(vscode: vscode): Observable<Options> { | ||
return Observable.create((observer: Observer<Options>) => { | ||
let disposable = vscode.workspace.onDidChangeConfiguration(e => { | ||
//if the omnisharp or csharp configuration are affected only then read the options | ||
if (e.affectsConfiguration('omnisharp') || e.affectsConfiguration('csharp')) { | ||
observer.next(Options.Read(vscode)); | ||
} | ||
}); | ||
|
||
return () => disposable.dispose(); | ||
}).publishBehavior(Options.Read(vscode)).refCount(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { vscode } from "../vscodeAdapter"; | ||
import { Options } from "../omnisharp/options"; | ||
import ShowInformationMessage from "./utils/ShowInformationMessage"; | ||
import { Observable } from "rxjs/Observable"; | ||
import Disposable from "../Disposable"; | ||
import 'rxjs/add/operator/filter'; | ||
import 'rxjs/add/operator/distinctUntilChanged'; | ||
|
||
function ConfigChangeObservable(optionObservable: Observable<Options>): Observable<Options> { | ||
let options: Options; | ||
return optionObservable. filter(newOptions => { | ||
let changed = (options && hasChanged(options, newOptions)); | ||
options = newOptions; | ||
return changed; | ||
}); | ||
} | ||
|
||
export function ShowOmniSharpConfigChangePrompt(optionObservable: Observable<Options>, vscode: vscode): Disposable { | ||
let subscription = ConfigChangeObservable(optionObservable) | ||
.subscribe(_ => { | ||
let message = "OmniSharp configuration has changed. Would you like to relaunch the OmniSharp server with your changes?"; | ||
ShowInformationMessage(vscode, message, { title: "Restart OmniSharp", command: 'o.restart' }); | ||
}); | ||
|
||
return new Disposable(subscription); | ||
} | ||
|
||
function hasChanged(oldOptions: Options, newOptions: Options): boolean { | ||
return (oldOptions.path != newOptions.path || | ||
oldOptions.useGlobalMono != newOptions.useGlobalMono || | ||
oldOptions.waitForDebugger != newOptions.waitForDebugger); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
test/unitTests/OptionObserver/OptionChangeObserver.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { use as chaiUse, expect, should } from 'chai'; | ||
import { updateConfig, getVSCodeWithConfig } from '../testAssets/Fakes'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import 'rxjs/add/observable/fromPromise'; | ||
import 'rxjs/add/operator/timeout'; | ||
import { vscode } from '../../../src/vscodeAdapter'; | ||
import { ShowOmniSharpConfigChangePrompt } from '../../../src/observers/OptionChangeObserver'; | ||
import { Subject } from 'rxjs/Subject'; | ||
import { Options } from '../../../src/omnisharp/options'; | ||
import { BehaviorSubject } from 'rxjs/BehaviorSubject'; | ||
|
||
chaiUse(require('chai-as-promised')); | ||
chaiUse(require('chai-string')); | ||
|
||
suite("OmniSharpConfigChangeObserver", () => { | ||
suiteSetup(() => should()); | ||
|
||
let doClickOk: () => void; | ||
let doClickCancel: () => void; | ||
let signalCommandDone: () => void; | ||
let commandDone: Promise<void>; | ||
let vscode: vscode; | ||
let infoMessage: string; | ||
let invokedCommand: string; | ||
let optionObservable: Subject<Options>; | ||
|
||
setup(() => { | ||
vscode = getVSCode(); | ||
optionObservable = new BehaviorSubject<Options>(Options.Read(vscode)); | ||
ShowOmniSharpConfigChangePrompt(optionObservable, vscode); | ||
commandDone = new Promise<void>(resolve => { | ||
signalCommandDone = () => { resolve(); }; | ||
}); | ||
}); | ||
|
||
[ | ||
{ config: "omnisharp", section: "path", value: "somePath" }, | ||
{ config: "omnisharp", section: "waitForDebugger", value: true }, | ||
{ config: "omnisharp", section: "useGlobalMono", value: "always" } | ||
|
||
].forEach(elem => { | ||
suite(`When the ${elem.config} ${elem.section} changes`, () => { | ||
setup(() => { | ||
expect(infoMessage).to.be.undefined; | ||
expect(invokedCommand).to.be.undefined; | ||
updateConfig(vscode, elem.config, elem.section, elem.value); | ||
optionObservable.next(Options.Read(vscode)); | ||
}); | ||
|
||
test(`The information message is shown`, async () => { | ||
expect(infoMessage).to.be.equal("OmniSharp configuration has changed. Would you like to relaunch the OmniSharp server with your changes?"); | ||
}); | ||
|
||
test('Given an information message if the user clicks cancel, the command is not executed', async () => { | ||
doClickCancel(); | ||
await expect(Observable.fromPromise(commandDone).timeout(1).toPromise()).to.be.rejected; | ||
expect(invokedCommand).to.be.undefined; | ||
}); | ||
|
||
test('Given an information message if the user clicks Restore, the command is executed', async () => { | ||
doClickOk(); | ||
await commandDone; | ||
expect(invokedCommand).to.be.equal("o.restart"); | ||
}); | ||
}); | ||
}); | ||
|
||
suite('Information Message is not shown on change in',() => { | ||
[ | ||
{ config: "csharp", section: 'disableCodeActions', value: true }, | ||
{ config: "csharp", section: 'testsCodeLens.enabled', value: false }, | ||
{ config: "omnisharp", section: 'referencesCodeLens.enabled', value: false }, | ||
{ config: "csharp", section: 'format.enable', value: false }, | ||
{ config: "omnisharp", section: 'useEditorFormattingSettings', value: false }, | ||
{ config: "omnisharp", section: 'maxProjectResults', value: 1000 }, | ||
{ config: "omnisharp", section: 'projectLoadTimeout', value: 1000 }, | ||
{ config: "omnisharp", section: 'autoStart', value: false }, | ||
{ config: "omnisharp", section: 'loggingLevel', value: 'verbose' } | ||
].forEach(elem => { | ||
test(`${elem.config} ${elem.section}`, async () => { | ||
expect(infoMessage).to.be.undefined; | ||
expect(invokedCommand).to.be.undefined; | ||
updateConfig(vscode, elem.config, elem.section, elem.value); | ||
optionObservable.next(Options.Read(vscode)); | ||
expect(infoMessage).to.be.undefined; | ||
}); | ||
}); | ||
}); | ||
|
||
teardown(() => { | ||
infoMessage = undefined; | ||
invokedCommand = undefined; | ||
doClickCancel = undefined; | ||
doClickOk = undefined; | ||
signalCommandDone = undefined; | ||
commandDone = undefined; | ||
}); | ||
|
||
function getVSCode(): vscode { | ||
let vscode = getVSCodeWithConfig(); | ||
vscode.window.showInformationMessage = async <T>(message: string, ...items: T[]) => { | ||
infoMessage = message; | ||
return new Promise<T>(resolve => { | ||
doClickCancel = () => { | ||
resolve(undefined); | ||
}; | ||
|
||
doClickOk = () => { | ||
resolve(...items); | ||
}; | ||
}); | ||
}; | ||
|
||
vscode.commands.executeCommand = (command: string, ...rest: any[]) => { | ||
invokedCommand = command; | ||
signalCommandDone(); | ||
return undefined; | ||
}; | ||
|
||
return vscode; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the line below are beyond my rx-fu, can you explain them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
publishBehavior is used to create a behavior observable which has the initial value as Option.Read(). refCount() is used so that the dispose function on the observable is called only when all the observers who susbcribed to this observable invoke unsubscribe. This test verifies this behavior https://github.com/OmniSharp/omnisharp-vscode/pull/2316/files#diff-dd9d0618b9edb503c00be5f531debc27R78