Skip to content

Add max length configuration for connection info in status bar #19276

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -176,6 +176,11 @@ The following Visual Studio Code settings are available for the mssql extension.
"event.saveAsExcel": ""
}
}

// Status bar
{
"mssql.statusBar.connectionInfoMaxLength"
}
```

See [customize options](https://github.com/Microsoft/vscode-mssql/wiki/customize-options) and [manage connection profiles](https://github.com/Microsoft/vscode-mssql/wiki/manage-connection-profiles) for more details.
3 changes: 3 additions & 0 deletions localization/xliff/vscode-mssql.xlf
Original file line number Diff line number Diff line change
@@ -2662,6 +2662,9 @@
<trans-unit id="mssql.connectionGroup.description">
<source xml:lang="en">The description of the connection group.</source>
</trans-unit>
<trans-unit id="mssql.statusBar.connectionInfoMaxLength.description">
<source xml:lang="en">The maximum number of characters to display for the connection info in the status bar. Set to -1 for no limit.</source>
</trans-unit>
<trans-unit id="mssql.maxRecentConnections">
<source xml:lang="en">The maximum number of recently used connections to store in the connection list.</source>
</trans-unit>
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1810,6 +1810,11 @@
"default": 45,
"minimum": 1,
"description": "%mssql.objectExplorer.expandTimeout%"
},
"mssql.statusBar.connectionInfoMaxLength": {
"type": "number",
"default": -1,
"description": "%mssql.statusBar.connectionInfoMaxLength.description%"
}
}
},
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
@@ -208,5 +208,6 @@
"mssql.walkthroughs.nextSteps.viewQueryPlan.altText": "Query plan visualization",
"mssql.walkthroughs.nextSteps.objectExplorerFilters.title": "Filter your Object Explorer Tree",
"mssql.walkthroughs.nextSteps.objectExplorerFilters.description": "Only see the database objects that matter most to you by applying filters to the Object Explorer tree.\nStart by clicking the filter button next to most folders in the Connections view.",
"mssql.walkthroughs.nextSteps.objectExplorerFilters.altText": "Object Explorer filters"
"mssql.walkthroughs.nextSteps.objectExplorerFilters.altText": "Object Explorer filters",
"mssql.statusBar.connectionInfoMaxLength.description": "The maximum number of characters to display for the connection info in the status bar. Set to -1 for no limit."
}
2 changes: 1 addition & 1 deletion src/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -115,7 +115,6 @@ export const errorPasswordNeedsReset = 18488;
export const errorLoginFailed = 18456;
export const errorFirewallRule = 40615;
export const errorSSLCertificateValidationFailed = -2146893019;
export const maxDisplayedStatusTextLength = 50;
export const outputContentTypeRoot = "root";
export const outputContentTypeMessages = "messages";
export const outputContentTypeResultsetMeta = "resultsetsMeta";
@@ -207,6 +206,7 @@ export const copilotDebugLogging = "mssql.copilotDebugLogging";
export const configSelectedAzureSubscriptions = "mssql.selectedAzureSubscriptions";
export const configShowActiveConnectionAsCodeLensSuggestion =
"mssql.query.showActiveConnectionAsCodeLensSuggestion";
export const configStatusBarConnectionInfoMaxLength = "statusBar.connectionInfoMaxLength";

// ToolsService Constants
export const serviceInstallingTo = "Installing SQL tools service to";
10 changes: 7 additions & 3 deletions src/models/connectionInfo.ts
Original file line number Diff line number Diff line change
@@ -137,15 +137,19 @@ export function getPicklistDetails(connCreds: IConnectionInfo): string {
* @param conn connection
* @returns display string that can be used in status view or other locations
*/
export function getConnectionDisplayString(creds: IConnectionInfo, trim: boolean = false): string {
export function getConnectionDisplayString(creds: IConnectionInfo, trimLength?: number): string {
const server = generateServerDisplayName(creds);
const database = generateDatabaseDisplayName(creds);
const user = getUserNameOrDomainLogin(creds);

let result = user ? `${server} : ${database} : ${user}` : `${server} : ${database}`;

if (trim && result.length > Constants.maxDisplayedStatusTextLength) {
result = result.slice(0, Constants.maxDisplayedStatusTextLength) + " \u2026"; // add ellipsis
if (trimLength) {
if (trimLength === 0) {
result = "";
} else if (trimLength > 0 && result.length > trimLength) {
result = result.slice(0, trimLength) + " \u2026"; // add ellipsis
}
}

return result;
7 changes: 6 additions & 1 deletion src/views/statusView.ts
Original file line number Diff line number Diff line change
@@ -186,7 +186,12 @@ export default class StatusView implements vscode.Disposable {
): void {
let bar = this.getStatusBar(fileUri);
bar.statusConnection.command = Constants.cmdChooseDatabase;
bar.statusConnection.text = `$(check) ${ConnInfo.getConnectionDisplayString(connCreds, true)}`;

let statusBarConnectionInfoMaxLength: number = vscode.workspace
.getConfiguration(Constants.extensionConfigSectionName)
.get(Constants.configStatusBarConnectionInfoMaxLength);
bar.statusConnection.text = `$(check) ${ConnInfo.getConnectionDisplayString(connCreds, statusBarConnectionInfoMaxLength)}`;

bar.statusConnection.tooltip = ConnInfo.getTooltip(connCreds, serverInfo);
this.showStatusBarItem(fileUri, bar.statusConnection);
this.sqlCmdModeChanged(fileUri, false);
Loading
Oops, something went wrong.
Loading
Oops, something went wrong.