Skip to content

Commit 135f8f8

Browse files
heftigchemzqm
authored andcommitted
Stabilize order of pythonCode (neoclide#50)
Actually fix neoclide#48
1 parent bcfc9ec commit 135f8f8

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/ultisnipsProvider.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { distinct, readdirAsync, readFileAsync, statAsync } from './util'
1717

1818
export class UltiSnippetsProvider extends BaseProvider {
1919
private snippetFiles: UltiSnipsFile[] = []
20-
private pythonCode: string
20+
private pythonCodes: Map<string, string> = new Map()
2121
private pyMethod: string
2222
private disposables: Disposable[] = []
2323
private directories: string[]
@@ -32,7 +32,7 @@ export class UltiSnippetsProvider extends BaseProvider {
3232
public async init(): Promise<void> {
3333
let { config, directories } = this
3434
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')
3636
if (hasPythonx && config.usePythonx) {
3737
this.pyMethod = 'pyx'
3838
} else {
@@ -43,12 +43,15 @@ export class UltiSnippetsProvider extends BaseProvider {
4343
await Promise.all(arr.map(({ filepath, directory, filetype }) => {
4444
return this.loadSnippetsFromFile(filetype, directory, filepath)
4545
}))
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) {
4750
let { nvim } = workspace
48-
let hash = crypto.createHash('md5').update(this.pythonCode).digest('hex')
51+
let hash = crypto.createHash('md5').update(pythonCode).digest('hex')
4952
let tmpfile = path.join(os.tmpdir(), `coc-ultisnips-${hash}.py`)
5053
if (!fs.existsSync(tmpfile)) {
51-
fs.writeFileSync(tmpfile, this.pythonCode, 'utf8')
54+
fs.writeFileSync(tmpfile, pythonCode, 'utf8')
5255
}
5356
let escaped = await nvim.call('fnameescape', tmpfile)
5457
workspace.nvim.command(`${this.pyMethod}file ${escaped}`, true)
@@ -117,7 +120,7 @@ export class UltiSnippetsProvider extends BaseProvider {
117120
if (this.trace == 'verbose') {
118121
this.channel.appendLine(`[Info ${(new Date()).toLocaleTimeString()}] Loaded ${snippets.length} snippets from: ${filepath}`)
119122
}
120-
this.pythonCode = this.pythonCode + '\n' + pythonCode
123+
this.pythonCodes.set(filepath, pythonCode)
121124
}
122125

123126
public async resolveSnippetBody(snippet: Snippet, range: Range, line: string): Promise<string> {

0 commit comments

Comments
 (0)