Skip to content

Commit 6990eff

Browse files
committed
1. add support for google protobuf
2. allow different language use different options(in my case, I need protobuf and cpp use different configure)
1 parent 73dcda5 commit 6990eff

File tree

4 files changed

+99
-17
lines changed

4 files changed

+99
-17
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Release history
44

5+
### CURRENT
6+
* add protobuf support(work with https://marketplace.visualstudio.com/items?itemName=peterj.proto)
7+
* add javascript/typescript support
8+
* allow different style & fallback style option for different languages
9+
510
### v 0.6.1
611
* clean up dependencies #9
712

package.json

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"onLanguage:objective-c",
2121
"onLanguage:java",
2222
"onLanguage:javascript",
23-
"onLanguage:typescript"
23+
"onLanguage:typescript",
24+
"onLanguage:proto"
2425
],
2526
"contributes": {
2627
"configuration": {
@@ -37,15 +38,88 @@
3738
"default": "clang-format",
3839
"description": "clang-format executable path"
3940
},
41+
// style
4042
"clang-format.style": {
4143
"type": "string",
4244
"default": "file",
4345
"description": "clang-format style.(-style=value, value can be file, LLVM, Google, Chromium, Mozilla, WebKit or json configure)"
4446
},
47+
// fallback style
4548
"clang-format.fallbackStyle": {
4649
"type": "string",
4750
"default": "LLVM",
4851
"description": "clang-format fallback style.(-fallback-style=value, value can be none, LLVM, Google, Chromium, Mozilla, WebKit)"
52+
},
53+
// every language can has it's own style & fallback style option, if not confirured, use the default value above
54+
"clang-format.language.cpp.style": {
55+
"type": "string",
56+
"default": "",
57+
"description": "clang-format fallback style for c++, left empty to use clang-format.style"
58+
},
59+
"clang-format.language.cpp.fallbackStyle": {
60+
"type": "string",
61+
"default": "",
62+
"description": "clang-format fallback style for c++, left empty to use clang-format.fallbackStyle"
63+
},
64+
"clang-format.language.c.style": {
65+
"type": "string",
66+
"default": "",
67+
"description": "clang-format fallback style for c, left empty to use clang-format.style"
68+
},
69+
"clang-format.language.c.fallbackStyle": {
70+
"type": "string",
71+
"default": "",
72+
"description": "clang-format fallback style for c, left empty to use clang-format.fallbackStyle"
73+
},
74+
"clang-format.language.objective-c.style": {
75+
"type": "string",
76+
"default": "",
77+
"description": "clang-format fallback style for objective-c, left empty to use clang-format.style"
78+
},
79+
"clang-format.language.objective-c.fallbackStyle": {
80+
"type": "string",
81+
"default": "",
82+
"description": "clang-format fallback style for objective-c, left empty to use clang-format.fallbackStyle"
83+
},
84+
"clang-format.language.java.style": {
85+
"type": "string",
86+
"default": "",
87+
"description": "clang-format fallback style for java, left empty to use clang-format.style"
88+
},
89+
"clang-format.language.java.fallbackStyle": {
90+
"type": "string",
91+
"default": "",
92+
"description": "clang-format fallback style for java, left empty to use clang-format.fallbackStyle"
93+
},
94+
"clang-format.language.javascript.style": {
95+
"type": "string",
96+
"default": "",
97+
"description": "clang-format fallback style for javascript, left empty to use clang-format.style"
98+
},
99+
"clang-format.language.javascript.fallbackStyle": {
100+
"type": "string",
101+
"default": "",
102+
"description": "clang-format fallback style for javascript, left empty to use clang-format.fallbackStyle"
103+
},
104+
"clang-format.language.typescript.style": {
105+
"type": "string",
106+
"default": "",
107+
"description": "clang-format fallback style for typescript, left empty to use clang-format.style"
108+
},
109+
"clang-format.language.typescript.fallbackStyle": {
110+
"type": "string",
111+
"default": "",
112+
"description": "clang-format fallback style for typescript, left empty to use clang-format.fallbackStyle"
113+
},
114+
"clang-format.language.proto.style": {
115+
"type": "string",
116+
"default": "",
117+
"description": "clang-format fallback style for proto, left empty to use clang-format.style"
118+
},
119+
"clang-format.language.proto.fallbackStyle": {
120+
"type": "string",
121+
"default": "",
122+
"description": "clang-format fallback style for proto, left empty to use clang-format.fallbackStyle"
49123
}
50124
}
51125
}

src/clangMode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
import vscode = require('vscode');
44

5-
const LANGUAGES: string[] = ['cpp', 'c', 'objective-c', 'java', 'javascript', 'typescript'];
5+
const LANGUAGES: string[] = ['cpp', 'c', 'objective-c', 'java', 'javascript', 'typescript', 'proto'];
66
export const MODES: vscode.DocumentFilter[] = LANGUAGES.map(language => ({ language, scheme: 'file' }));

src/extension.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,24 +120,27 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
120120
return this.defaultConfigure.executable;
121121
}
122122

123-
private getStyle() {
124-
let ret = vscode.workspace.getConfiguration('clang-format').get<string>('style');
123+
private getStyle(document: vscode.TextDocument) {
124+
let ret = vscode.workspace.getConfiguration('clang-format').get<string>(`language.${document.languageId}.style`);
125125
if (ret.trim()) {
126-
ret = ret.trim();
126+
return ret.trim();
127+
}
128+
129+
ret = vscode.workspace.getConfiguration('clang-format').get<string>('style');
130+
if (ret && ret.trim()) {
131+
return ret.trim();
127132
} else {
128-
ret = this.defaultConfigure.style;
133+
return this.defaultConfigure.style;
129134
}
130-
131-
// Custom style
132-
// if (ret.match(/[\\\{\" ]/)) {
133-
// return `"${ret.replace(/([\\\"])/g, "\\$1")}"`
134-
// }
135-
136-
return ret;
137135
}
138136

139-
private getFallbackStyle() {
140-
let strConf = vscode.workspace.getConfiguration('clang-format').get<string>('fallbackStyle');
137+
private getFallbackStyle(document: vscode.TextDocument) {
138+
let strConf = vscode.workspace.getConfiguration('clang-format').get<string>(`language.${document.languageId}.fallbackStyle`);
139+
if (strConf.trim()) {
140+
return strConf;
141+
}
142+
143+
strConf = vscode.workspace.getConfiguration('clang-format').get<string>('fallbackStyle');
141144
if (strConf.trim()) {
142145
return strConf;
143146
}
@@ -173,8 +176,8 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
173176

174177
var formatArgs = [
175178
'-output-replacements-xml',
176-
`-style=${this.getStyle()}`,
177-
`-fallback-style=${this.getFallbackStyle()}`,
179+
`-style=${this.getStyle(document)}`,
180+
`-fallback-style=${this.getFallbackStyle(document)}`,
178181
`-assume-filename=${document.fileName}`,
179182
];
180183

0 commit comments

Comments
 (0)