From c474a8c63b48f0555d99c4a398798b54292f920a Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Fri, 6 Mar 2020 18:40:52 +0800 Subject: [PATCH] use custom temp fodler --- src/server/typescriptServiceClient.ts | 6 +++--- src/server/utils/process.ts | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/server/typescriptServiceClient.ts b/src/server/typescriptServiceClient.ts index 1729c6b..fa7a6b1 100644 --- a/src/server/typescriptServiceClient.ts +++ b/src/server/typescriptServiceClient.ts @@ -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 diff --git a/src/server/utils/process.ts b/src/server/utils/process.ts index 763c616..3b8c6fd 100644 --- a/src/server/utils/process.ts +++ b/src/server/utils/process.ts @@ -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(