use custom temp fodler

This commit is contained in:
Qiming Zhao 2020-03-06 18:40:52 +08:00
parent c1c3017081
commit c474a8c63b
2 changed files with 15 additions and 7 deletions

View file

@ -15,7 +15,7 @@ import { ITypeScriptServiceClient, ServerResponse } from './typescriptService'
import API from './utils/api'
import { TsServerLogLevel, TypeScriptServiceConfiguration } from './utils/configuration'
import Logger from './utils/logger'
import { fork, getTempFile, IForkOptions, makeRandomHexString } from './utils/process'
import { fork, getTempFile, getTempDirectory, IForkOptions, makeRandomHexString } from './utils/process'
import { languageIds } from './utils/languageModeIds'
import Tracer from './utils/tracer'
import { inferredProjectConfig } from './utils/tsconfig'
@ -770,9 +770,9 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
if (this.apiVersion.gte(API.v222)) {
const isRoot = process.getuid && process.getuid() == 0
if (this._configuration.tsServerLogLevel !== TsServerLogLevel.Off && !isRoot) {
const logDir = os.tmpdir()
const logDir = getTempDirectory()
if (logDir) {
this.tsServerLogFile = path.join(logDir, `coc-nvim-tsc.log`)
this.tsServerLogFile = path.join(logDir, `tsserver.log`)
this.info('TSServer log file :', this.tsServerLogFile)
} else {
this.tsServerLogFile = null

View file

@ -6,7 +6,7 @@ import cp from 'child_process'
import net from 'net'
import os from 'os'
import path from 'path'
import { workspace } from 'coc.nvim'
import fs from 'fs'
import Logger from './logger'
export interface IForkOptions {
@ -24,6 +24,14 @@ export function makeRandomHexString(length: number): string {
return result
}
export function getTempDirectory(): string {
let dir = path.join(os.tmpdir(), `coc.nvim-${process.pid}`)
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir)
}
return dir
}
function generatePipeName(): string {
return getPipeName(makeRandomHexString(40))
}
@ -33,14 +41,14 @@ function getPipeName(name: string): string {
if (process.platform === 'win32') {
return '\\\\.\\pipe\\' + fullName + '-sock'
}
const tmpdir = getTempDirectory()
// Mac/Unix: use socket file
return path.join(os.tmpdir(), fullName + '.sock')
return path.join(tmpdir, fullName + '.sock')
}
export function getTempFile(name: string): string {
const fullName = 'coc-nvim-' + name
return path.join(os.tmpdir(), fullName + '.sock')
return path.join(getTempDirectory(), fullName + '.sock')
}
function generatePatchedEnv(