@@ -12,7 +12,7 @@ import {
12
12
} from './languageModes' ;
13
13
14
14
export function getHTMLMode ( htmlLanguageService : HTMLLanguageService , workspace : Workspace ) : LanguageMode {
15
- let htmlDocuments = getLanguageModelCache < HTMLDocument > ( 10 , 60 , document => htmlLanguageService . parseHTMLDocument ( document ) ) ;
15
+ const htmlDocuments = getLanguageModelCache < HTMLDocument > ( 10 , 60 , document => htmlLanguageService . parseHTMLDocument ( document ) ) ;
16
16
return {
17
17
getId ( ) {
18
18
return 'html' ;
@@ -21,15 +21,13 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
21
21
return htmlLanguageService . getSelectionRanges ( document , [ position ] ) [ 0 ] ;
22
22
} ,
23
23
doComplete ( document : TextDocument , position : Position , documentContext : DocumentContext , settings = workspace . settings ) {
24
- let options = settings && settings . html && settings . html . suggest ;
25
- let doAutoComplete = settings && settings . html && settings . html . autoClosingTags ;
26
- if ( doAutoComplete ) {
27
- options . hideAutoCompleteProposals = true ;
28
- }
29
- options . attributeDefaultValue = settings . html . completion . attributeDefaultValue ?? 'doublequotes' ;
24
+ const htmlSettings = settings ?. html ;
25
+ const options = merge ( htmlSettings ?. suggest , { } ) ;
26
+ options . hideAutoCompleteProposals = htmlSettings ?. autoClosingTags === true ;
27
+ options . attributeDefaultValue = htmlSettings ?. completion ?. attributeDefaultValue ?? 'doublequotes' ;
30
28
31
29
const htmlDocument = htmlDocuments . get ( document ) ;
32
- let completionList = htmlLanguageService . doComplete2 ( document , position , htmlDocument , documentContext , options ) ;
30
+ const completionList = htmlLanguageService . doComplete2 ( document , position , htmlDocument , documentContext , options ) ;
33
31
return completionList ;
34
32
} ,
35
33
async doHover ( document : TextDocument , position : Position , settings ?: Settings ) {
@@ -45,26 +43,21 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
45
43
return htmlLanguageService . findDocumentSymbols ( document , htmlDocuments . get ( document ) ) ;
46
44
} ,
47
45
async format ( document : TextDocument , range : Range , formatParams : FormattingOptions , settings = workspace . settings ) {
48
- let formatSettings : HTMLFormatConfiguration = settings && settings . html && settings . html . format ;
49
- if ( formatSettings ) {
50
- formatSettings = merge ( formatSettings , { } ) ;
51
- } else {
52
- formatSettings = { } ;
53
- }
46
+ const formatSettings : HTMLFormatConfiguration = merge ( settings ?. html ?. format , { } ) ;
54
47
if ( formatSettings . contentUnformatted ) {
55
48
formatSettings . contentUnformatted = formatSettings . contentUnformatted + ',script' ;
56
49
} else {
57
50
formatSettings . contentUnformatted = 'script' ;
58
51
}
59
- formatSettings = merge ( formatParams , formatSettings ) ;
52
+ merge ( formatParams , formatSettings ) ;
60
53
return htmlLanguageService . format ( document , range , formatSettings ) ;
61
54
} ,
62
55
async getFoldingRanges ( document : TextDocument ) : Promise < FoldingRange [ ] > {
63
56
return htmlLanguageService . getFoldingRanges ( document ) ;
64
57
} ,
65
58
async doAutoClose ( document : TextDocument , position : Position ) {
66
- let offset = document . offsetAt ( position ) ;
67
- let text = document . getText ( ) ;
59
+ const offset = document . offsetAt ( position ) ;
60
+ const text = document . getText ( ) ;
68
61
if ( offset > 0 && text . charAt ( offset - 1 ) . match ( / [ > \/ ] / g) ) {
69
62
return htmlLanguageService . doTagComplete ( document , position , htmlDocuments . get ( document ) ) ;
70
63
}
@@ -92,9 +85,11 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
92
85
}
93
86
94
87
function merge ( src : any , dst : any ) : any {
95
- for ( const key in src ) {
96
- if ( src . hasOwnProperty ( key ) ) {
97
- dst [ key ] = src [ key ] ;
88
+ if ( src ) {
89
+ for ( const key in src ) {
90
+ if ( src . hasOwnProperty ( key ) ) {
91
+ dst [ key ] = src [ key ] ;
92
+ }
98
93
}
99
94
}
100
95
return dst ;
0 commit comments