Repository: parcel-bundler/parcel
File: packages/reporters/lsp-reporter/src/LspReporter.js (JavaScript)

Code before:
};

const BASEDIR = fs.realpathSync(path.join(os.tmpdir(), 'parcel-lsp'));
const SOCKET_FILE = path.join(BASEDIR, `parcel-${process.pid}`);
const META_FILE = path.join(BASEDIR, `parcel-${process.pid}.json`);

let workspaceDiagnostics: DefaultMap<
  string,
  Array<Diagnostic>,
> = new DefaultMap(() => []);

const getWorkspaceDiagnostics = (): Array<PublishDiagnostic> =>
  [...workspaceDiagnostics].map(([uri, diagnostics]) => ({uri, diagnostics}));

let server;
let connections: Array<MessageConnection> = [];

let bundleGraphDeferrable =
  makeDeferredWithPromise<?BundleGraph<PackagedBundle>>();
let bundleGraph: Promise<?BundleGraph<PackagedBundle>> =
  bundleGraphDeferrable.promise;

let watchStarted = false;
let lspStarted = false;
let watchStartPromise;

async function watchLspActive(): Promise<FSWatcher> {
  const lspFileName = 'lsp-server';

  // Check for lsp-server when reporter is first started
  try {
    await fs.promises.access(
      path.join(BASEDIR, 'lsp-server'),
      fs.constants.F_OK,
    );
    lspStarted = true;
  } catch {
    //
  }

  return fs.watch(BASEDIR, (eventType: string, filename: string) => {
    switch (eventType) {
      case 'rename':
        if (filename === lspFileName) {
          fs.access(
            path.join(BASEDIR, 'lsp-server'),
            fs.constants.F_OK,
            err => {
              if (err) {
                lspStarted = false;
              } else {

Review comment (suggestion):
```suggestion

const LSP_SENTINEL_FILENAME = 'lsp-server';
const LSP_SENTINEL_FILE = path.join(BASEDIR, LSP_SENTINEL_FILENAME);

```

Code after:
};

const BASEDIR = fs.realpathSync(path.join(os.tmpdir(), 'parcel-lsp'));
const SOCKET_FILE = path.join(BASEDIR, `parcel-${process.pid}`);
const META_FILE = path.join(BASEDIR, `parcel-${process.pid}.json`);

let workspaceDiagnostics: DefaultMap<
  string,
  Array<Diagnostic>,
> = new DefaultMap(() => []);

const getWorkspaceDiagnostics = (): Array<PublishDiagnostic> =>
  [...workspaceDiagnostics].map(([uri, diagnostics]) => ({uri, diagnostics}));

let server;
let connections: Array<MessageConnection> = [];

let bundleGraphDeferrable =
  makeDeferredWithPromise<?BundleGraph<PackagedBundle>>();
let bundleGraph: Promise<?BundleGraph<PackagedBundle>> =
  bundleGraphDeferrable.promise;

let watchStarted = false;
let lspStarted = false;
let watchStartPromise;

const LSP_SENTINEL_FILENAME = 'lsp-server';
const LSP_SENTINEL_FILE = path.join(BASEDIR, LSP_SENTINEL_FILENAME);

async function watchLspActive(): Promise<FSWatcher> {
  // Check for lsp-server when reporter is first started
  try {
    await fs.promises.access(LSP_SENTINEL_FILE, fs.constants.F_OK);
    lspStarted = true;
  } catch {
    //
  }

  return fs.watch(BASEDIR, (eventType: string, filename: string) => {
    switch (eventType) {
      case 'rename':
        if (filename === LSP_SENTINEL_FILENAME) {
          fs.access(LSP_SENTINEL_FILE, fs.constants.F_OK, err => {
            if (err) {
              lspStarted = false;
            } else {
              lspStarted = true;
            }
          });
        }
    }