Skip to content

Commit 5881a2a

Browse files
authored
Merge pull request #185 from jedmao/multi-root
v0.12.0 - Support multi-root workspaces
2 parents 437750a + d6c2fde commit 5881a2a

5 files changed

Lines changed: 45 additions & 28 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.12.0
2+
- Support multi-root workspaces [`#174`](https://github.com/editorconfig/editorconfig-vscode/issues/174).
3+
14
## 0.11.1
25
- Update EditorConfig dependency.
36

package.json

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66
"version": "0.11.1",
77
"icon": "EditorConfig_icon.png",
88
"engines": {
9-
"vscode": "^1.11.0"
9+
"vscode": "^1.19.2"
1010
},
1111
"author": "EditorConfig Team",
1212
"license": "MIT",
1313
"categories": [
1414
"Other"
1515
],
16+
"keywords": [
17+
"editor",
18+
"config",
19+
"multi-root ready"
20+
],
1621
"homepage": "https://github.com/editorconfig/editorconfig-vscode/blob/master/README.md",
1722
"repository": {
1823
"type": "git",
@@ -32,24 +37,39 @@
3237
"contributes": {
3338
"commands": [
3439
{
35-
"command": "vscode.generateeditorconfig",
36-
"title": "EditorConfig: Generate"
40+
"command": "EditorConfig.generate",
41+
"title": "Generate .editorconfig"
3742
}
38-
]
43+
],
44+
"menus": {
45+
"commandPalette": [
46+
{
47+
"command": "EditorConfig.generate",
48+
"when": "explorerResourceIsFolder"
49+
}
50+
],
51+
"explorer/context": [
52+
{
53+
"command": "EditorConfig.generate",
54+
"when": "explorerResourceIsFolder",
55+
"group": "EditorConfig@1"
56+
}
57+
]
58+
}
3959
},
4060
"dependencies": {
4161
"editorconfig": "^0.15.0",
4262
"lodash.compact": "^3.0.1",
4363
"lodash.get": "^4.4.2"
4464
},
4565
"devDependencies": {
46-
"@types/lodash": "^4.14.77",
47-
"@types/mocha": "^2.2.43",
48-
"@types/node": "^8.0.34",
66+
"@types/lodash": "^4.14.93",
67+
"@types/mocha": "^2.2.46",
68+
"@types/node": "^9.3.0",
4969
"rimraf": "^2.6.2",
50-
"tslint": "^5.7.0",
51-
"typescript": "^2.5.3",
52-
"vscode": "^1.1.6",
70+
"tslint": "^5.9.1",
71+
"typescript": "^2.6.2",
72+
"vscode": "^1.1.10",
5373
"vscode-test-utils": "0.0.9"
5474
},
5575
"scripts": {

src/DocumentWatcher.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class DocumentWatcher implements EditorConfigProvider {
103103
const ext = languageExtensionMap[doc.languageId] || doc.languageId;
104104
return path.join(
105105
...compact([
106-
workspace.rootPath,
106+
workspace.getWorkspaceFolder(doc.uri),
107107
`${doc.fileName}.${ext}`
108108
])
109109
);
@@ -126,7 +126,7 @@ class DocumentWatcher implements EditorConfigProvider {
126126
return;
127127
}
128128
const fileName = this.getFileName(doc);
129-
const relativePath = workspace.asRelativePath(fileName);
129+
const relativePath = workspace.asRelativePath(fileName, true);
130130

131131
if (this.docToConfigMap[fileName]) {
132132
this.log(`${relativePath}: Applying configuration map...`);
@@ -156,7 +156,7 @@ class DocumentWatcher implements EditorConfigProvider {
156156
}
157157

158158
const doc = editor.document;
159-
const relativePath = workspace.asRelativePath(doc.fileName);
159+
const relativePath = workspace.asRelativePath(doc.fileName, true);
160160
const editorconfigSettings = this.getSettingsForDocument(doc);
161161

162162
if (!editorconfigSettings) {
@@ -176,7 +176,7 @@ class DocumentWatcher implements EditorConfigProvider {
176176
}
177177

178178
private onConfigChanged() {
179-
const workspaceConfig = workspace.getConfiguration('editor');
179+
const workspaceConfig = workspace.getConfiguration('editor', null);
180180
const detectIndentation = workspaceConfig.get<boolean>('detectIndentation');
181181

182182
this.defaults = (detectIndentation) ? {} : {

src/commands/generateEditorConfig.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,16 @@ import * as fs from 'fs';
22
import * as path from 'path';
33
import {
44
workspace,
5-
window
5+
window,
6+
Uri
67
} from 'vscode';
78

89
/**
910
* Generate a .editorconfig file in the root of the workspace based on the
1011
* current vscode settings.
1112
*/
12-
export function generateEditorConfig() {
13-
if (!workspace.rootPath) {
14-
window.showInformationMessage(
15-
'Please open a folder before generating an .editorconfig file'
16-
);
17-
return;
18-
}
19-
20-
const editorConfigFile = path.join(workspace.rootPath, '.editorconfig');
13+
export function generateEditorConfig(uri: Uri) {
14+
const editorConfigFile = path.join(uri.fsPath, '.editorconfig');
2115

2216
fs.stat(editorConfigFile, (err, stats) => {
2317

@@ -32,14 +26,14 @@ export function generateEditorConfig() {
3226

3327
if (stats.isFile()) {
3428
window.showErrorMessage(
35-
'A .editorconfig file already exists in your workspace.'
29+
'An .editorconfig file already exists in this workspace.'
3630
);
3731
}
3832
});
3933

4034
function writeFile() {
41-
const editor = workspace.getConfiguration('editor');
42-
const files = workspace.getConfiguration('files');
35+
const editor = workspace.getConfiguration('editor', uri);
36+
const files = workspace.getConfiguration('files', uri);
4337

4438
const settingsLines = ['root = true', '', '[*]'];
4539
function addSetting(key: string, value?: string | number | boolean): void {

src/editorConfigMain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function activate(ctx: ExtensionContext): void {
3737

3838
// register a command handler to generate a .editorconfig file
3939
commands.registerCommand(
40-
'vscode.generateeditorconfig',
40+
'EditorConfig.generate',
4141
generateEditorConfig
4242
);
4343
}

0 commit comments

Comments
 (0)