From 207b00f23a8d4a923d8388894ed4ba698fe65e30 Mon Sep 17 00:00:00 2001 From: abist Date: Mon, 9 Dec 2019 18:07:50 -0800 Subject: [PATCH] fixed intellisense bug --- src/controllers/connectionManager.ts | 19 ++++++++------- src/controllers/mainController.ts | 32 ++++++++++++++------------ src/controllers/queryRunner.ts | 2 +- src/controllers/vscodeWrapper.ts | 2 +- src/languageservice/serviceclient.ts | 10 ++++---- src/models/sqlOutputContentProvider.ts | 4 ++-- src/models/utils.ts | 2 +- src/views/statusView.ts | 4 ++-- 8 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/controllers/connectionManager.ts b/src/controllers/connectionManager.ts index 72b621990..edeb25f4a 100644 --- a/src/controllers/connectionManager.ts +++ b/src/controllers/connectionManager.ts @@ -788,8 +788,8 @@ export default class ConnectionManager { return this.connectionUI.removeProfile(); } - public onDidCloseTextDocument(doc: vscode.TextDocument): void { - let docUri: string = doc.uri.toString(); + public async onDidCloseTextDocument(doc: vscode.TextDocument): Promise { + let docUri: string = doc.uri.toString(true); // If this file isn't connected, then don't do anything if (!this.isConnected(docUri)) { @@ -797,17 +797,17 @@ export default class ConnectionManager { } // Disconnect the document's connection when we close it - this.disconnect(docUri); + await this.disconnect(docUri); } public onDidOpenTextDocument(doc: vscode.TextDocument): void { - let uri = doc.uri.toString(); + let uri = doc.uri.toString(true); if (doc.languageId === 'sql' && typeof(this._connections[uri]) === 'undefined') { this.statusView.notConnected(uri); } } - public transferFileConnection(oldFileUri: string, newFileUri: string): void { + public async transferFileConnection(oldFileUri: string, newFileUri: string): Promise { // Is the new file connected or the old file not connected? if (!this.isConnected(oldFileUri) || this.isConnected(newFileUri)) { return; @@ -815,11 +815,10 @@ export default class ConnectionManager { // Connect the saved uri and disconnect the untitled uri on successful connection let creds: Interfaces.IConnectionCredentials = this._connections[oldFileUri].credentials; - this.connect(newFileUri, creds).then(result => { - if (result) { - this.disconnect(oldFileUri); - } - }); + let result = await this.connect(newFileUri, creds) + if (result) { + await this.disconnect(oldFileUri); + } } private getIsServerLinux(osVersion: string): string { diff --git a/src/controllers/mainController.ts b/src/controllers/mainController.ts index bb30a5356..22d29411f 100644 --- a/src/controllers/mainController.ts +++ b/src/controllers/mainController.ts @@ -251,7 +251,7 @@ export default class MainController implements vscode.Disposable { this.scriptNode(node, ScriptOperation.Alter))); // Add handlers for VS Code generated commands - this._vscodeWrapper.onDidCloseTextDocument(params => this.onDidCloseTextDocument(params)); + this._vscodeWrapper.onDidCloseTextDocument(async (params) => await this.onDidCloseTextDocument(params)); this._vscodeWrapper.onDidOpenTextDocument(params => this.onDidOpenTextDocument(params)); this._vscodeWrapper.onDidSaveTextDocument(params => this.onDidSaveTextDocument(params)); this._vscodeWrapper.onDidChangeConfiguration(params => this.onDidChangeConfiguration(params)); @@ -280,7 +280,7 @@ export default class MainController implements vscode.Disposable { } const selectStatement = await this._scriptingService.script(node, nodeUri, operation); const editor = await this._untitledSqlDocumentService.newQuery(selectStatement); - let uri = editor.document.uri.toString(); + let uri = editor.document.uri.toString(true); let title = path.basename(editor.document.fileName); const queryUriPromise = new Deferred(); await this.connectionManager.connect(uri, connectionCreds, queryUriPromise); @@ -740,7 +740,7 @@ export default class MainController implements vscode.Disposable { if (this.canRunCommand()) { // from the object explorer context menu const editor = await this._untitledSqlDocumentService.newQuery(content); - const uri = editor.document.uri.toString(); + const uri = editor.document.uri.toString(true); if (node) { // connect to the node if the command came from the context const connectionCreds = node.connectionCredentials; @@ -749,9 +749,9 @@ export default class MainController implements vscode.Disposable { // connect it first await this.createObjectExplorerSession(node.connectionCredentials); } - this._statusview.languageFlavorChanged(uri.toString(), Constants.mssqlProviderName); - await this.connectionManager.connect(uri.toString(), connectionCreds); - this._statusview.sqlCmdModeChanged(uri.toString(), false); + this._statusview.languageFlavorChanged(uri, Constants.mssqlProviderName); + await this.connectionManager.connect(uri, connectionCreds); + this._statusview.sqlCmdModeChanged(uri, false); await this.connectionManager.connectionStore.removeRecentlyUsed(connectionCreds); return true; } else { @@ -762,7 +762,7 @@ export default class MainController implements vscode.Disposable { if (credentials) { await this.createObjectExplorerSession(credentials); } - this._statusview.sqlCmdModeChanged(uri.toString(), false); + this._statusview.sqlCmdModeChanged(uri, false); return true; } } @@ -800,12 +800,12 @@ export default class MainController implements vscode.Disposable { * or a renamed file * @param doc The document that was closed */ - public onDidCloseTextDocument(doc: vscode.TextDocument): void { + public async onDidCloseTextDocument(doc: vscode.TextDocument): Promise { if (this._connectionMgr === undefined) { // Avoid processing events before initialization is complete return; } - let closedDocumentUri: string = doc.uri.toString(); + let closedDocumentUri: string = doc.uri.toString(true); let closedDocumentUriScheme: string = doc.uri.scheme; // Stop timers if they have been started @@ -825,17 +825,17 @@ export default class MainController implements vscode.Disposable { closedDocumentUriScheme === LocalizedConstants.untitledScheme && this._lastSavedTimer.getDuration() < Constants.untitledSaveTimeThreshold) { // Untitled file was saved and connection will be transfered - this._connectionMgr.transferFileConnection(closedDocumentUri, this._lastSavedUri); + await this._connectionMgr.transferFileConnection(closedDocumentUri, this._lastSavedUri); // If there was an openTextDoc event just before this closeTextDoc event then we know it was a rename } else if (this._lastOpenedUri && this._lastOpenedTimer.getDuration() < Constants.renamedOpenTimeThreshold) { // File was renamed and connection will be transfered - this._connectionMgr.transferFileConnection(closedDocumentUri, this._lastOpenedUri); + await this._connectionMgr.transferFileConnection(closedDocumentUri, this._lastOpenedUri); } else { // Pass along the close event to the other handlers for a normal closed file - this._connectionMgr.onDidCloseTextDocument(doc); + await this._connectionMgr.onDidCloseTextDocument(doc); this._outputContentProvider.onDidCloseTextDocument(doc); } @@ -859,14 +859,15 @@ export default class MainController implements vscode.Disposable { this._connectionMgr.onDidOpenTextDocument(doc); if (doc && doc.languageId === Constants.languageId) { - this._statusview.languageFlavorChanged(doc.uri.toString(), Constants.mssqlProviderName); + // set encoding to false + this._statusview.languageFlavorChanged(doc.uri.toString(true), Constants.mssqlProviderName); } // Setup properties incase of rename this._lastOpenedTimer = new Utils.Timer(); this._lastOpenedTimer.start(); if (doc && doc.uri) { - this._lastOpenedUri = doc.uri.toString(); + this._lastOpenedUri = doc.uri.toString(true); } } @@ -881,7 +882,8 @@ export default class MainController implements vscode.Disposable { return; } - let savedDocumentUri: string = doc.uri.toString(); + // Set encoding to false by giving true as argument + let savedDocumentUri: string = doc.uri.toString(true); // Keep track of which file was last saved and when for detecting the case when we save an untitled document to disk this._lastSavedTimer = new Utils.Timer(); diff --git a/src/controllers/queryRunner.ts b/src/controllers/queryRunner.ts index d1dff89f0..a478a21a8 100644 --- a/src/controllers/queryRunner.ts +++ b/src/controllers/queryRunner.ts @@ -507,7 +507,7 @@ export default class QueryRunner { * @param selection The selection range to select */ public async setEditorSelection(selection: ISelectionData): Promise { - const docExists = this._vscodeWrapper.textDocuments.find(textDoc => textDoc.uri.toString() === this.uri); + const docExists = this._vscodeWrapper.textDocuments.find(textDoc => textDoc.uri.toString(true) === this.uri); if (docExists) { let column = vscode.ViewColumn.One; const doc = await this._vscodeWrapper.openTextDocument(this._vscodeWrapper.parseUri(this.uri)); diff --git a/src/controllers/vscodeWrapper.ts b/src/controllers/vscodeWrapper.ts index f15aeb3dc..fc35fd4c3 100644 --- a/src/controllers/vscodeWrapper.ts +++ b/src/controllers/vscodeWrapper.ts @@ -63,7 +63,7 @@ export default class VscodeWrapper { public get activeTextEditorUri(): string { if (typeof vscode.window.activeTextEditor !== 'undefined' && typeof vscode.window.activeTextEditor.document !== 'undefined') { - return vscode.window.activeTextEditor.document.uri.toString(); + return vscode.window.activeTextEditor.document.uri.toString(true); } return undefined; } diff --git a/src/languageservice/serviceclient.ts b/src/languageservice/serviceclient.ts index 70d090a18..412a343da 100644 --- a/src/languageservice/serviceclient.ts +++ b/src/languageservice/serviceclient.ts @@ -314,11 +314,11 @@ export default class SqlToolsServiceClient { private createResourceClient(resourcePath: string): LanguageClient { // Options to control the language client let clientOptions: LanguageClientOptions = { - documentSelector: ['sql'], - synchronize: { - configurationSection: 'mssql' - }, - errorHandler: new LanguageClientErrorHandler(this._vscodeWrapper) + // documentSelector: ['sql'], + // synchronize: { + // configurationSection: 'mssql' + // }, + // errorHandler: new LanguageClientErrorHandler(this._vscodeWrapper) }; // add resource provider path here let serverOptions = this.generateResourceServiceServerOptions(resourcePath); diff --git a/src/models/sqlOutputContentProvider.ts b/src/models/sqlOutputContentProvider.ts index 77f369b7a..4b361a5ee 100644 --- a/src/models/sqlOutputContentProvider.ts +++ b/src/models/sqlOutputContentProvider.ts @@ -278,12 +278,12 @@ export class SqlOutputContentProvider { public onDidCloseTextDocument(doc: vscode.TextDocument): void { for (let [key, value] of this._queryResultsMap.entries()) { // closed text document related to a results window we are holding - if (doc.uri.toString() === value.queryRunner.uri) { + if (doc.uri.toString(true) === value.queryRunner.uri) { value.flaggedForDeletion = true; } // "closed" a results window we are holding - if (doc.uri.toString() === key) { + if (doc.uri.toString(true) === key) { value.timeout = this.setRunnerDeletionTimeout(key); } } diff --git a/src/models/utils.ts b/src/models/utils.ts index b7824c206..00477b005 100644 --- a/src/models/utils.ts +++ b/src/models/utils.ts @@ -117,7 +117,7 @@ export function getActiveTextEditor(): vscode.TextEditor { export function getActiveTextEditorUri(): string { if (typeof vscode.window.activeTextEditor !== 'undefined' && typeof vscode.window.activeTextEditor.document !== 'undefined') { - return vscode.window.activeTextEditor.document.uri.toString(); + return vscode.window.activeTextEditor.document.uri.toString(true); } return ''; } diff --git a/src/views/statusView.ts b/src/views/statusView.ts index 04634c83b..9c61815b3 100644 --- a/src/views/statusView.ts +++ b/src/views/statusView.ts @@ -278,7 +278,7 @@ export default class StatusView implements vscode.Disposable { if (typeof editor !== 'undefined') { // Hide the most recently shown status bar this.hideLastShownStatusBar(); - const fileUri = editor.document.uri.toString(); + const fileUri = editor.document.uri.toString(true); const bar = this._statusBars[fileUri]; if (bar) { this.showStatusBarItem(fileUri, bar.statusLanguageFlavor); @@ -291,7 +291,7 @@ export default class StatusView implements vscode.Disposable { private onDidCloseTextDocument(doc: vscode.TextDocument): void { // Remove the status bar associated with the document - this.destroyStatusBar(doc.uri.toString()); + this.destroyStatusBar(doc.uri.toString(true)); } private showStatusBarItem(fileUri: string, statusBarItem: vscode.StatusBarItem): void {