#110 - Support for workspaces with multiple folders

This commit is contained in:
Elio Struyf
2021-10-01 10:18:48 +02:00
parent bf1639cac7
commit cac009b773
4 changed files with 32 additions and 6 deletions
+2 -1
View File
@@ -1,6 +1,6 @@
# Change Log
## [4.1.0] - 2021-XX-XX
## [4.1.0] - 2021-XX-XX - [Release Notes](https://beta.frontmatter.codes/updates/v4.1.0)
### ✨ New features
@@ -8,6 +8,7 @@
### 🎨 Enhancements
- [#110](https://github.com/estruyf/vscode-front-matter/issues/110): Add support for workspaces with multiple folders
- [#117](https://github.com/estruyf/vscode-front-matter/issues/117): Allow to specify a singleline of text in the metadata fields
- [#119](https://github.com/estruyf/vscode-front-matter/issues/119): Multi-select support for choice fields
- [#121](https://github.com/estruyf/vscode-front-matter/issues/121): Choice fields support ID/title objects as well as a regular string
+25 -2
View File
@@ -6,6 +6,7 @@ import uniqBy = require("lodash.uniqby");
import { Template } from "./Template";
import { Notifications } from "../helpers/Notifications";
import { Settings } from "../helpers";
import { existsSync } from 'fs';
export const WORKSPACE_PLACEHOLDER = `[[workspace]]`;
@@ -114,8 +115,31 @@ export class Folders {
*/
public static getWorkspaceFolder(): Uri | undefined {
const folders = workspace.workspaceFolders;
if (folders && folders.length > 0) {
if (folders && folders.length === 1) {
return folders[0].uri;
} else if (folders && folders.length > 1) {
let projectFolder = undefined;
for (const folder of folders) {
if (!projectFolder && existsSync(join(folder.uri.fsPath, Settings.globalFile))) {
projectFolder = folder.uri;
}
}
if (!projectFolder) {
window.showWorkspaceFolderPick({
placeHolder: `Please select the main workspace folder for Front Matter to use.`
}).then(selectedFolder => {
if (selectedFolder) {
Settings.createGlobalFile(selectedFolder.uri);
// Full reload to make sure the whole extension is reloaded correctly
commands.executeCommand(`workbench.action.reloadWindow`);
}
});
}
return projectFolder;
}
return undefined;
}
@@ -126,7 +150,6 @@ export class Folders {
public static getProjectFolderName(): string {
const wsFolder = Folders.getWorkspaceFolder();
if (wsFolder) {
// const projectFolder = wsFolder?.fsPath.split('\\').join('/').split('/').pop();
return basename(wsFolder.fsPath);
}
return "";
-1
View File
@@ -1,5 +1,4 @@
import { workspace, Uri } from "vscode";
import { CONFIG_KEY, SETTING_TEMPLATES_FOLDER } from "../constants";
import { join } from "path";
import * as fs from "fs";
import { Notifications } from "../helpers/Notifications";
+5 -2
View File
@@ -1,5 +1,5 @@
import { Notifications } from './Notifications';
import { workspace } from 'vscode';
import { Uri, workspace } from 'vscode';
import * as vscode from 'vscode';
import { TaxonomyType } from '../models';
import { SETTING_TAXONOMY_TAGS, SETTING_TAXONOMY_CATEGORIES, CONFIG_KEY } from '../constants';
@@ -9,8 +9,8 @@ import { existsSync, readFileSync, watch, writeFileSync } from 'fs';
import { Extension } from './Extension';
export class Settings {
public static globalFile = "frontmatter.json";
private static config: vscode.WorkspaceConfiguration;
private static globalFile = "frontmatter.json";
private static globalConfig: any;
public static init() {
@@ -131,7 +131,10 @@ export class Settings {
*/
public static createTeamSettings() {
const wsFolder = Folders.getWorkspaceFolder();
this.createGlobalFile(wsFolder);
}
public static createGlobalFile(wsFolder: Uri | undefined | null) {
const initialConfig = {
"$schema": `https://${Extension.getInstance().isBetaVersion() ? `beta.` : ``}frontmatter.codes/frontmatter.schema.json`
};