Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
master: Closes #430. Using vscode variables pattern for multi workspc…
…es support
- Loading branch information
Showing
13 changed files
with
99 additions
and
50 deletions.
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
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
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,17 @@ | ||
import { workspace } from 'vscode'; | ||
|
||
const WORKSPACE_PLACEHOLDER = /\$\{workspaceFolder(?:\:(.+))?}/; | ||
|
||
const parseWorkspacePath = (file: string) => { | ||
if (!WORKSPACE_PLACEHOLDER.test(file)) return file; | ||
const [ _, workspaceName ] = file.match(WORKSPACE_PLACEHOLDER) || []; | ||
if (workspaceName) { | ||
const workspacePath = (workspace.workspaceFolders.find(w => w.name === workspaceName) || { uri: { fsPath: '.' } }).uri.fsPath; | ||
file = file.replace(WORKSPACE_PLACEHOLDER, `${workspacePath}`); | ||
} else { | ||
file = file.replace(WORKSPACE_PLACEHOLDER, `.`) | ||
} | ||
return file; | ||
} | ||
|
||
export default parseWorkspacePath; |
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,20 @@ | ||
import { workspace, Uri } from 'vscode'; | ||
import path from 'path'; | ||
|
||
const relativeToWorkspace = (file: string) => { | ||
const workspaceFolder = workspace.getWorkspaceFolder(Uri.file(file)); | ||
const isSavedWorkSpace = !!(workspace.workspaceFile && workspace.workspaceFile.scheme !== 'untitled'); | ||
if (isSavedWorkSpace && workspaceFolder) { | ||
// when using workspace files | ||
file = workspace.asRelativePath(file, false); | ||
file = `\${workspaceFolder:${workspaceFolder.name}}/${file}`; | ||
} else if (workspaceFolder && workspace.workspaceFolders.length === 1) { | ||
// when vscode opens a folder | ||
file = workspace.asRelativePath(file, false); | ||
file = `\${workspaceFolder}${path.sep}${file}`; | ||
} | ||
// if no folder is open or not saved workspace, just return | ||
return file; | ||
} | ||
|
||
export default relativeToWorkspace; |
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
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
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,21 @@ | ||
import ConfigManager from '@sqltools/core/config-manager'; | ||
import { window, StatusBarItem, StatusBarAlignment } from 'vscode'; | ||
import { EXT_NAME } from '@sqltools/core/constants'; | ||
|
||
let statusBar: StatusBarItem & { setText: (text?: string) => void }; | ||
|
||
statusBar = <typeof statusBar>window.createStatusBarItem(StatusBarAlignment.Left, 10); | ||
statusBar.tooltip = 'Select a connection'; | ||
statusBar.command = `${EXT_NAME}.selectConnection`; | ||
|
||
statusBar.setText = text => (statusBar.text = `$(database) ${text || 'Connect'}`); | ||
|
||
statusBar.setText(); | ||
|
||
const updateVisibility = () => ConfigManager.showStatusbar ? statusBar.show() : statusBar.hide(); | ||
|
||
updateVisibility(); | ||
|
||
ConfigManager.addOnUpdateHook(updateVisibility); | ||
|
||
export default statusBar; |
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