@@ -19,6 +19,13 @@ interface FileConfiguration {
19
19
readonly preferences : Proto . UserPreferences ;
20
20
}
21
21
22
+ interface FormattingOptions {
23
+
24
+ readonly tabSize : number | undefined ;
25
+
26
+ readonly insertSpaces : boolean | undefined ;
27
+ }
28
+
22
29
function areFileConfigurationsEqual ( a : FileConfiguration , b : FileConfiguration ) : boolean {
23
30
return equals ( a , b ) ;
24
31
}
@@ -51,21 +58,21 @@ export default class FileConfigurationManager extends Disposable {
51
58
}
52
59
}
53
60
54
- private getFormattingOptions (
55
- document : vscode . TextDocument
56
- ) : vscode . FormattingOptions | undefined {
57
- const editor = vscode . window . visibleTextEditors . find ( editor => editor . document . fileName === document . fileName ) ;
58
- return editor
59
- ? {
60
- tabSize : editor . options . tabSize ,
61
- insertSpaces : editor . options . insertSpaces
62
- } as vscode . FormattingOptions
63
- : undefined ;
61
+ private getFormattingOptions ( document : vscode . TextDocument ) : FormattingOptions | undefined {
62
+ const editor = vscode . window . visibleTextEditors . find ( editor => editor . document . uri . toString ( ) === document . uri . toString ( ) ) ;
63
+ if ( ! editor ) {
64
+ return undefined ;
65
+ }
66
+
67
+ return {
68
+ tabSize : typeof editor . options . tabSize === 'number' ? editor . options . tabSize : undefined ,
69
+ insertSpaces : typeof editor . options . insertSpaces === 'boolean' ? editor . options . insertSpaces : undefined ,
70
+ } ;
64
71
}
65
72
66
73
public async ensureConfigurationOptions (
67
74
document : vscode . TextDocument ,
68
- options : vscode . FormattingOptions ,
75
+ options : FormattingOptions ,
69
76
token : vscode . CancellationToken
70
77
) : Promise < void > {
71
78
const file = this . client . toOpenTsFilePath ( document ) ;
@@ -122,7 +129,7 @@ export default class FileConfigurationManager extends Disposable {
122
129
123
130
private getFileOptions (
124
131
document : vscode . TextDocument ,
125
- options : vscode . FormattingOptions
132
+ options : FormattingOptions
126
133
) : FileConfiguration {
127
134
return {
128
135
formatOptions : this . getFormatOptions ( document , options ) ,
@@ -132,7 +139,7 @@ export default class FileConfigurationManager extends Disposable {
132
139
133
140
private getFormatOptions (
134
141
document : vscode . TextDocument ,
135
- options : vscode . FormattingOptions
142
+ options : FormattingOptions
136
143
) : Proto . FormatCodeSettings {
137
144
const config = vscode . workspace . getConfiguration (
138
145
isTypeScriptDocument ( document ) ? 'typescript.format' : 'javascript.format' ,
0 commit comments