Skip to content

Commit

Permalink
fixed intellisense bug
Browse files Browse the repository at this point in the history
  • Loading branch information
abist committed Dec 10, 2019
1 parent 0c701f4 commit 207b00f
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 37 deletions.
19 changes: 9 additions & 10 deletions src/controllers/connectionManager.ts
Expand Up @@ -788,38 +788,37 @@ 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<void> {
let docUri: string = doc.uri.toString(true);

// If this file isn't connected, then don't do anything
if (!this.isConnected(docUri)) {
return;
}

// 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<void> {
// Is the new file connected or the old file not connected?
if (!this.isConnected(oldFileUri) || this.isConnected(newFileUri)) {
return;
}

// 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 {
Expand Down
32 changes: 17 additions & 15 deletions src/controllers/mainController.ts
Expand Up @@ -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));
Expand Down Expand Up @@ -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<boolean>();
await this.connectionManager.connect(uri, connectionCreds, queryUriPromise);
Expand Down Expand Up @@ -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;
Expand All @@ -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(<IConnectionProfile>connectionCreds);
return true;
} else {
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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<void> {
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
Expand All @@ -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);
}

Expand All @@ -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);
}
}

Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/queryRunner.ts
Expand Up @@ -507,7 +507,7 @@ export default class QueryRunner {
* @param selection The selection range to select
*/
public async setEditorSelection(selection: ISelectionData): Promise<void> {
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));
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/vscodeWrapper.ts
Expand Up @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions src/languageservice/serviceclient.ts
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/models/sqlOutputContentProvider.ts
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/utils.ts
Expand Up @@ -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 '';
}
Expand Down
4 changes: 2 additions & 2 deletions src/views/statusView.ts
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down

0 comments on commit 207b00f

Please sign in to comment.