@@ -21,10 +21,8 @@ export class Document {
2121 detectIndentation : boolean = true ,
2222 fallbackTabSize : number = DefaultSettings . editor . tabSize ,
2323 ) {
24- const doc = this . getTextDocument ( ) ;
25- const { extension, type } = doc
26- ? detectDocumentType ( doc . uri , doc . getText ( ) )
27- : { extension : '' , type : DocumentType . YAML } ;
24+ const doc = this . getTextDocument ( ) as TextDocument ;
25+ const { extension, type } = detectDocumentType ( doc . uri , doc . getText ( ) ) ;
2826
2927 this . extension = extension ;
3028 this . documentType = type ;
@@ -138,11 +136,11 @@ export class Document {
138136 }
139137
140138 public getText ( range ?: Range ) {
141- return this . getTextDocument ( ) ?. getText ( range ) ?? '' ;
139+ return this . getTextDocument ( ) ?. getText ( range ) ;
142140 }
143141
144- public getLines ( ) : string [ ] {
145- return this . getText ( ) . split ( '\n' ) ;
142+ public getLines ( ) : string [ ] | undefined {
143+ return this . getText ( ) ? .split ( '\n' ) ;
146144 }
147145
148146 public positionAt ( offset : number ) {
@@ -158,7 +156,7 @@ export class Document {
158156 }
159157
160158 public contents ( ) {
161- return this . getTextDocument ( ) ?. getText ( ) ?? '' ;
159+ return this . getTextDocument ( ) ?. getText ( ) ;
162160 }
163161
164162 public metadata ( ) : DocumentMetadata {
@@ -170,7 +168,7 @@ export class Document {
170168 cfnType : this . cfnFileType ,
171169 languageId : this . languageId ?? '' ,
172170 version : this . version ?? 0 ,
173- lineCount : this . lineCount ?? - 1 ,
171+ lineCount : this . lineCount ?? 0 ,
174172 } ;
175173 }
176174
@@ -190,6 +188,9 @@ export class Document {
190188
191189 private detectIndentationFromContent ( ) : number | undefined {
192190 const content = this . contents ( ) ;
191+ if ( ! content ) {
192+ return undefined ;
193+ }
193194 const lines = content . split ( '\n' ) ;
194195
195196 const maxLinesToAnalyze = Math . min ( lines . length , 30 ) ;
0 commit comments