@@ -17,7 +17,7 @@ import { distinct, readdirAsync, readFileAsync, statAsync } from './util'
17
17
18
18
export class UltiSnippetsProvider extends BaseProvider {
19
19
private snippetFiles : UltiSnipsFile [ ] = [ ]
20
- private pythonCode : string
20
+ private pythonCodes : Map < string , string > = new Map ( )
21
21
private pyMethod : string
22
22
private disposables : Disposable [ ] = [ ]
23
23
private directories : string [ ]
@@ -32,7 +32,7 @@ export class UltiSnippetsProvider extends BaseProvider {
32
32
public async init ( ) : Promise < void > {
33
33
let { config, directories } = this
34
34
let hasPythonx = await workspace . nvim . call ( 'has' , [ 'pythonx' ] )
35
- this . pythonCode = await readFileAsync ( path . join ( __dirname , '../python/ultisnips.py' ) , 'utf8' )
35
+ let pythonCode = await readFileAsync ( path . join ( __dirname , '../python/ultisnips.py' ) , 'utf8' )
36
36
if ( hasPythonx && config . usePythonx ) {
37
37
this . pyMethod = 'pyx'
38
38
} else {
@@ -43,12 +43,15 @@ export class UltiSnippetsProvider extends BaseProvider {
43
43
await Promise . all ( arr . map ( ( { filepath, directory, filetype } ) => {
44
44
return this . loadSnippetsFromFile ( filetype , directory , filepath )
45
45
} ) )
46
- if ( this . pythonCode ) {
46
+ let pythonPaths = Array . from ( this . pythonCodes . keys ( ) )
47
+ pythonPaths . sort ( )
48
+ pythonCode += '\n' + pythonPaths . map ( p => this . pythonCodes . get ( p ) ) . join ( '\n' )
49
+ if ( pythonCode ) {
47
50
let { nvim } = workspace
48
- let hash = crypto . createHash ( 'md5' ) . update ( this . pythonCode ) . digest ( 'hex' )
51
+ let hash = crypto . createHash ( 'md5' ) . update ( pythonCode ) . digest ( 'hex' )
49
52
let tmpfile = path . join ( os . tmpdir ( ) , `coc-ultisnips-${ hash } .py` )
50
53
if ( ! fs . existsSync ( tmpfile ) ) {
51
- fs . writeFileSync ( tmpfile , this . pythonCode , 'utf8' )
54
+ fs . writeFileSync ( tmpfile , pythonCode , 'utf8' )
52
55
}
53
56
let escaped = await nvim . call ( 'fnameescape' , tmpfile )
54
57
workspace . nvim . command ( `${ this . pyMethod } file ${ escaped } ` , true )
@@ -117,7 +120,7 @@ export class UltiSnippetsProvider extends BaseProvider {
117
120
if ( this . trace == 'verbose' ) {
118
121
this . channel . appendLine ( `[Info ${ ( new Date ( ) ) . toLocaleTimeString ( ) } ] Loaded ${ snippets . length } snippets from: ${ filepath } ` )
119
122
}
120
- this . pythonCode = this . pythonCode + '\n' + pythonCode
123
+ this . pythonCodes . set ( filepath , pythonCode )
121
124
}
122
125
123
126
public async resolveSnippetBody ( snippet : Snippet , range : Range , line : string ) : Promise < string > {
0 commit comments