11import * as vscode from 'vscode' ;
22import cp = require( 'child_process' ) ;
33import path = require( 'path' ) ;
4- import { MODES } from './clangMode' ;
5- import { getBinPath } from './clangPath' ;
4+ import { MODES ,
5+ ALIAS } from './clangMode' ;
6+ import { getBinPath } from './clangPath' ;
67import sax = require( 'sax' ) ;
78
89export let outputChannel = vscode . window . createOutputChannel ( 'Clang-Format' ) ;
@@ -41,7 +42,7 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
4142 byte : 0 ,
4243 offset : 0
4344 } ;
44- let byteToOffset = function ( editInfo : { length : number , offset : number } ) {
45+ let byteToOffset = function ( editInfo : { length : number , offset : number } ) {
4546 let offset = editInfo . offset ;
4647 let length = editInfo . length ;
4748
@@ -70,20 +71,20 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
7071 }
7172
7273 switch ( tag . name ) {
73- case 'replacements' :
74- return ;
75-
76- case 'replacement' :
77- currentEdit = {
78- length : parseInt ( tag . attributes [ 'length' ] . toString ( ) ) ,
79- offset : parseInt ( tag . attributes [ 'offset' ] . toString ( ) ) ,
80- text : ''
81- } ;
82- byteToOffset ( currentEdit ) ;
83- break ;
84-
85- default :
86- reject ( `Unexpected tag ${ tag . name } ` ) ;
74+ case 'replacements' :
75+ return ;
76+
77+ case 'replacement' :
78+ currentEdit = {
79+ length : parseInt ( tag . attributes [ 'length' ] . toString ( ) ) ,
80+ offset : parseInt ( tag . attributes [ 'offset' ] . toString ( ) ) ,
81+ text : ''
82+ } ;
83+ byteToOffset ( currentEdit ) ;
84+ break ;
85+
86+ default :
87+ reject ( `Unexpected tag ${ tag . name } ` ) ;
8788 }
8889
8990 } ;
@@ -133,8 +134,12 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
133134 } ) ;
134135 }
135136
137+ private getLanguage ( document : vscode . TextDocument ) : string {
138+ return ALIAS [ document . languageId ] || document . languageId ;
139+ }
140+
136141 private getStyle ( document : vscode . TextDocument ) {
137- let ret = vscode . workspace . getConfiguration ( 'clang-format' ) . get < string > ( `language.${ document . languageId } .style` ) ;
142+ let ret = vscode . workspace . getConfiguration ( 'clang-format' ) . get < string > ( `language.${ this . getLanguage ( document ) } .style` ) ;
138143 if ( ret . trim ( ) ) {
139144 return ret . trim ( ) ;
140145 }
@@ -148,7 +153,7 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
148153 }
149154
150155 private getFallbackStyle ( document : vscode . TextDocument ) {
151- let strConf = vscode . workspace . getConfiguration ( 'clang-format' ) . get < string > ( `language.${ document . languageId } .fallbackStyle` ) ;
156+ let strConf = vscode . workspace . getConfiguration ( 'clang-format' ) . get < string > ( `language.${ this . getLanguage ( document ) } .fallbackStyle` ) ;
152157 if ( strConf . trim ( ) ) {
153158 return strConf ;
154159 }
0 commit comments