diff --git a/package.json b/package.json index 3badda3..47a47bb 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "JavaScript", "Objective-C", "Clang", - "LLVM" + "LLVM", + "Protobuf" ], "main": "./out/src/extension", "activationEvents": [ @@ -34,6 +35,7 @@ "onLanguage:javascript", "onLanguage:typescript", "onLanguage:proto", + "onLanguage:proto3", "onLanguage:apex" ], "contributes": { diff --git a/src/clangMode.ts b/src/clangMode.ts index 7079858..47bb974 100644 --- a/src/clangMode.ts +++ b/src/clangMode.ts @@ -2,11 +2,16 @@ import vscode = require('vscode'); +export const ALIAS = { + 'proto3': 'proto' +}; + let languages: string[] = []; -for (let l of ['cpp', 'c', 'objective-c', 'objective-cpp', 'java', 'javascript', 'typescript', 'proto', 'apex']) { - if (vscode.workspace.getConfiguration('clang-format').get('language.' + l + '.enable')) { +for (let l of ['cpp', 'c', 'objective-c', 'objective-cpp', 'java', 'javascript', 'typescript', 'proto', 'proto3', 'apex']) { + let confKey = `language.${ALIAS[l] || l}.enable`; + if (vscode.workspace.getConfiguration('clang-format').get(confKey)) { languages.push(l); } } -export const MODES: vscode.DocumentFilter[] = languages.map((language) => ({ language, scheme: 'file' })); \ No newline at end of file +export const MODES: vscode.DocumentFilter[] = languages.map((language) => ({language, scheme: 'file'})); \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index 4b364d6..150e6ad 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,8 +1,9 @@ import * as vscode from 'vscode'; import cp = require('child_process'); import path = require('path'); -import { MODES } from './clangMode'; -import { getBinPath } from './clangPath'; +import {MODES, + ALIAS} from './clangMode'; +import {getBinPath} from './clangPath'; import sax = require('sax'); export let outputChannel = vscode.window.createOutputChannel('Clang-Format'); @@ -41,7 +42,7 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma byte: 0, offset: 0 }; - let byteToOffset = function (editInfo: { length: number, offset: number }) { + let byteToOffset = function(editInfo: { length: number, offset: number }) { let offset = editInfo.offset; let length = editInfo.length; @@ -70,20 +71,20 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma } switch (tag.name) { - case 'replacements': - return; - - case 'replacement': - currentEdit = { - length: parseInt(tag.attributes['length'].toString()), - offset: parseInt(tag.attributes['offset'].toString()), - text: '' - }; - byteToOffset(currentEdit); - break; - - default: - reject(`Unexpected tag ${tag.name}`); + case 'replacements': + return; + + case 'replacement': + currentEdit = { + length: parseInt(tag.attributes['length'].toString()), + offset: parseInt(tag.attributes['offset'].toString()), + text: '' + }; + byteToOffset(currentEdit); + break; + + default: + reject(`Unexpected tag ${tag.name}`); } }; @@ -133,8 +134,12 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma }); } + private getLanguage(document: vscode.TextDocument): string { + return ALIAS[document.languageId] || document.languageId; + } + private getStyle(document: vscode.TextDocument) { - let ret = vscode.workspace.getConfiguration('clang-format').get(`language.${document.languageId}.style`); + let ret = vscode.workspace.getConfiguration('clang-format').get(`language.${this.getLanguage(document)}.style`); if (ret.trim()) { return ret.trim(); } @@ -148,7 +153,7 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma } private getFallbackStyle(document: vscode.TextDocument) { - let strConf = vscode.workspace.getConfiguration('clang-format').get(`language.${document.languageId}.fallbackStyle`); + let strConf = vscode.workspace.getConfiguration('clang-format').get(`language.${this.getLanguage(document)}.fallbackStyle`); if (strConf.trim()) { return strConf; }