Skip to content
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

Add language flavor to fix #978 #988

Merged
merged 1 commit into from
Sep 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
{
"version": "0.1.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Gulp task",
"program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js",
"args": [
"ext:localization:xliff-to-package.nls"
]
},
{
"name": "Launch Extension",
"type": "extensionHost",
Expand Down
18 changes: 18 additions & 0 deletions localization/xliff/enu/constants/localizedConstants.enu.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,24 @@
<trans-unit id="msgCannotSaveMultipleSelections">
<source xml:lang="en">Save results command cannot be used with multiple selections.</source>
</trans-unit>
<trans-unit id="mssqlProviderName">
<source xml:lang="en">MSSQL</source>
</trans-unit>
<trans-unit id="noneProviderName">
<source xml:lang="en">None</source>
</trans-unit>
<trans-unit id="chooseSqlLang">
<source xml:lang="en">Choose SQL Language</source>
</trans-unit>
<trans-unit id="flavorChooseLanguage">
<source xml:lang="en">Choose SQL Language</source>
</trans-unit>
<trans-unit id="flavorDescriptionMssql">
<source xml:lang="en">Use T-SQL intellisense and syntax error checking on current document</source>
</trans-unit>
<trans-unit id="flavorDescriptionNone">
<source xml:lang="en">Disable intellisense and syntax error checking on current document</source>
</trans-unit>
</body>
</file>
</xliff>
3 changes: 3 additions & 0 deletions localization/xliff/enu/localizedPackage.json.enu.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<trans-unit id="extension.chooseDatabase">
<source xml:lang="en">Use Database</source>
</trans-unit>
<trans-unit id="extension.chooseLanguageFlavor">
<source xml:lang="en">Choose SQL handler for this file</source>
</trans-unit>
<trans-unit id="extension.showGettingStarted">
<source xml:lang="en">Getting Started Guide</source>
</trans-unit>
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@
"title": "%extension.chooseDatabase%",
"category": "MS SQL"
},
{
"command": "extension.chooseLanguageFlavor",
"title": "%extension.chooseLanguageFlavor%",
"category": "MS SQL"
},
{
"command": "extension.showGettingStarted",
"title": "%extension.showGettingStarted%",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"extension.disconnect":"Disconnect",
"extension.manageProfiles":"Manage Connection Profiles",
"extension.chooseDatabase":"Use Database",
"extension.chooseLanguageFlavor":"Choose SQL handler for this file",
"extension.showGettingStarted":"Getting Started Guide",
"extension.newQuery":"New Query",
"extension.rebuildIntelliSenseCache":"Refresh IntelliSense Cache",
Expand Down
3 changes: 3 additions & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
export const languageId = 'sql';
export const extensionName = 'mssql';
export const extensionConfigSectionName = 'mssql';
export const mssqlProviderName = 'MSSQL';
export const noneProviderName = 'None';
export const connectionApplicationName = 'vscode-mssql';
export const outputChannelName = 'MSSQL';
export const connectionConfigFilename = 'settings.json';
Expand All @@ -12,6 +14,7 @@ export const cmdCancelQuery = 'extension.cancelQuery';
export const cmdConnect = 'extension.connect';
export const cmdDisconnect = 'extension.disconnect';
export const cmdChooseDatabase = 'extension.chooseDatabase';
export const cmdChooseLanguageFlavor = 'extension.chooseLanguageFlavor';
export const cmdShowReleaseNotes = 'extension.showReleaseNotes';
export const cmdShowGettingStarted = 'extension.showGettingStarted';
export const cmdNewQuery = 'extension.newQuery';
Expand Down
22 changes: 22 additions & 0 deletions src/controllers/connectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,27 @@ export default class ConnectionManager {
});
}

public onChooseLanguageFlavor(): Promise<boolean> {
const fileUri = this._vscodeWrapper.activeTextEditorUri;
if (fileUri && this._vscodeWrapper.isEditingSqlFile) {
return this._connectionUI.promptLanguageFlavor().then(flavor => {
if (!flavor) {
return false;
}
this.statusView.languageFlavorChanged(fileUri, flavor);
SqlToolsServerClient.instance.sendNotification(LanguageServiceContracts.LanguageFlavorChangedNotification.type,
<LanguageServiceContracts.DidChangeLanguageFlavorParams> {
uri: fileUri,
language: 'sql',
flavor: flavor
});
});
} else {
this._vscodeWrapper.showWarningMessage(LocalizedConstants.msgOpenSqlFile);
return Promise.resolve(false);
}
}

// close active connection, if any
public onDisconnect(): Promise<boolean> {
return this.disconnect(this.vscodeWrapper.activeTextEditorUri);
Expand Down Expand Up @@ -517,6 +538,7 @@ export default class ConnectionManager {
this._connections[fileUri] = connectionInfo;

self.statusView.connecting(fileUri, connectionCreds);
self.statusView.languageFlavorChanged(fileUri, Constants.mssqlProviderName);
self.vscodeWrapper.logToOutputChannel(
Utils.formatString(LocalizedConstants.msgConnecting, connectionCreds.server, fileUri)
);
Expand Down
30 changes: 29 additions & 1 deletion src/controllers/mainController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export default class MainController implements vscode.Disposable {
this._event.on(Constants.cmdManageConnectionProfiles, () => { self.runAndLogErrors(self.onManageProfiles(), 'onManageProfiles'); });
this.registerCommand(Constants.cmdChooseDatabase);
this._event.on(Constants.cmdChooseDatabase, () => { self.runAndLogErrors(self.onChooseDatabase(), 'onChooseDatabase') ; } );
this.registerCommand(Constants.cmdChooseLanguageFlavor);
this._event.on(Constants.cmdChooseLanguageFlavor, () => { self.runAndLogErrors(self.onChooseLanguageFlavor(), 'onChooseLanguageFlavor') ; } );
this.registerCommand(Constants.cmdCancelQuery);
this._event.on(Constants.cmdCancelQuery, () => { self.onCancelQuery(); });
this.registerCommand(Constants.cmdShowGettingStarted);
Expand Down Expand Up @@ -146,7 +148,7 @@ export default class MainController implements vscode.Disposable {
SqlToolsServerClient.instance.initialize(self._context).then(serverResult => {

// Init status bar
self._statusview = new StatusView();
self._statusview = new StatusView(self._vscodeWrapper);

// Init CodeAdapter for use when user response to questions is needed
self._prompter = new CodeAdapter();
Expand All @@ -170,6 +172,12 @@ export default class MainController implements vscode.Disposable {

self.showReleaseNotesPrompt();

// Handle case where SQL file is the 1st opened document
const activeTextEditor = this._vscodeWrapper.activeTextEditor;
if (activeTextEditor && this._vscodeWrapper.isEditingSqlFile) {
this.onDidOpenTextDocument(activeTextEditor.document);
}

Utils.logDebug('activated.');
self._initialized = true;
resolve(true);
Expand Down Expand Up @@ -206,6 +214,22 @@ export default class MainController implements vscode.Disposable {
return Promise.resolve(false);
}

/**
* Choose a language flavor for the SQL document. Should be either "MSSQL" or "Other"
* to indicate that intellisense and other services should not be provided
*/
private onChooseLanguageFlavor(): Promise<boolean> {
if (this.canRunCommand() && this.validateTextDocumentHasFocus()) {
const fileUri = this._vscodeWrapper.activeTextEditorUri;
if (fileUri && this._vscodeWrapper.isEditingSqlFile) {
this._connectionMgr.onChooseLanguageFlavor();
} else {
this._vscodeWrapper.showWarningMessage(LocalizedConstants.msgOpenSqlFile);
}
}
return Promise.resolve(false);
}

/**
* Close active connection, if any
*/
Expand Down Expand Up @@ -578,6 +602,10 @@ export default class MainController implements vscode.Disposable {
}
this._connectionMgr.onDidOpenTextDocument(doc);

if (this._vscodeWrapper.isEditingSqlFile) {
this._statusview.languageFlavorChanged(doc.uri.toString(), Constants.mssqlProviderName);
}

// Setup properties incase of rename
this._lastOpenedTimer = new Utils.Timer();
this._lastOpenedTimer.start();
Expand Down
9 changes: 9 additions & 0 deletions src/controllers/vscodeWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ export default class VscodeWrapper {
return vscode.window.activeTextEditor;
}

/**
* An [event](#Event) which fires when the [active editor](#window.activeTextEditor)
* has changed. *Note* that the event also fires when the active editor changes
* to `undefined`.
*/
public get onDidChangeActiveTextEditor(): vscode.Event<vscode.TextEditor> {
return vscode.window.onDidChangeActiveTextEditor;
}

/**
* get the current textDocument; any that are open?
*/
Expand Down
15 changes: 7 additions & 8 deletions src/languageservice/serviceclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ interface IMessage {
*/
class LanguageClientErrorHandler {

private vscodeWrapper: VscodeWrapper;

/**
* Creates an instance of LanguageClientErrorHandler.
* @memberOf LanguageClientErrorHandler
*/
constructor() {
constructor(private vscodeWrapper?: VscodeWrapper) {
if (!this.vscodeWrapper) {
this.vscodeWrapper = new VscodeWrapper();
}
Expand Down Expand Up @@ -113,7 +111,6 @@ export default class SqlToolsServiceClient {

// VS Code Language Client
private _client: LanguageClient = undefined;

// getter method for the Language Client
private get client(): LanguageClient {
return this._client;
Expand All @@ -127,7 +124,8 @@ export default class SqlToolsServiceClient {
private _config: IConfig,
private _server: ServerProvider,
private _logger: Logger,
private _statusView: StatusView) {
private _statusView: StatusView,
private _vscodeWrapper: VscodeWrapper) {
}

// gets or creates the singleton SQL Tools service client instance
Expand All @@ -142,8 +140,9 @@ export default class SqlToolsServiceClient {
let downloadProvider = new ServiceDownloadProvider(config, logger, serverStatusView, httpClient,
decompressProvider);
let serviceProvider = new ServerProvider(downloadProvider, config, serverStatusView);
let statusView = new StatusView();
this._instance = new SqlToolsServiceClient(config, serviceProvider, logger, statusView);
let vscodeWrapper = new VscodeWrapper();
let statusView = new StatusView(vscodeWrapper);
this._instance = new SqlToolsServiceClient(config, serviceProvider, logger, statusView, vscodeWrapper);
}
return this._instance;
}
Expand Down Expand Up @@ -281,7 +280,7 @@ export default class SqlToolsServiceClient {
synchronize: {
configurationSection: 'mssql'
},
errorHandler: new LanguageClientErrorHandler()
errorHandler: new LanguageClientErrorHandler(this._vscodeWrapper)
};

// cache the client instance for later use
Expand Down
27 changes: 27 additions & 0 deletions src/models/contracts/languageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,30 @@ export class StatusChangeParams {


// ------------------------------- </ Status Sent Event > ----------------------------------

// ------------------------------- < Language Flavor Changed Event > ------------------------------------
/**
* Language flavor change event parameters
*/
export class DidChangeLanguageFlavorParams {
/**
* URI identifying the text document
*/
public uri: string;
/**
* text document's language
*/
public language: string;
/**
* Sub-flavor for the langauge, e.g. 'MSSQL' for a SQL Server connection or 'Other' for any other SQL flavor
*/
public flavor: string;
}

/**
* Notification sent when the language flavor is changed
*/
export namespace LanguageFlavorChangedNotification {
export const type: NotificationType<DidChangeLanguageFlavorParams> = { get method(): string { return 'connection/languageflavorchanged'; } };
}

32 changes: 32 additions & 0 deletions src/views/connectionUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ enum ManageProfileTask {
Remove
}

export interface ISqlProviderItem extends vscode.QuickPickItem {
providerId: string;
}

export class ConnectionUI {
private _errorOutputChannel: vscode.OutputChannel;

Expand Down Expand Up @@ -89,6 +93,34 @@ export class ConnectionUI {
});
}

public promptLanguageFlavor(): Promise<string> {
const self = this;
return new Promise<string>((resolve, reject) => {
let picklist: ISqlProviderItem[] = [
{
label: LocalizedConstants.mssqlProviderName,
description: LocalizedConstants.flavorDescriptionMssql,
providerId: Constants.mssqlProviderName
},
{
label: LocalizedConstants.noneProviderName,
description: LocalizedConstants.flavorDescriptionNone,
providerId: Constants.noneProviderName
}
];
self.promptItemChoice({
placeHolder: LocalizedConstants.flavorChooseLanguage,
matchOnDescription: true
}, picklist).then(selection => {
if (selection) {
resolve(selection.providerId);
} else {
resolve(undefined);
}
});
});
}

// requests the user to choose an item from the list
private promptItemChoice<T extends vscode.QuickPickItem>(options: vscode.QuickPickOptions, choices: T[]): Promise<T> {
let question: IQuestion = {
Expand Down
Loading