File: working_files.h

package info (click to toggle)
asymptote 2.85%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 43,264 kB
  • sloc: cpp: 210,491; ansic: 98,376; python: 14,568; javascript: 6,629; sh: 4,301; perl: 1,566; lisp: 1,505; makefile: 764; yacc: 554; lex: 446; xml: 182; objc: 177
file content (72 lines) | stat: -rw-r--r-- 2,161 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once

#include "LibLsp/lsp/lsp_diagnostic.h"
#include "LibLsp/lsp/AbsolutePath.h"
#include "LibLsp/lsp/textDocument/did_change.h"
#include "LibLsp/lsp/textDocument/did_close.h"
#include "LibLsp/lsp/textDocument/did_open.h"
#include <mutex>
#include <string>
#include <memory>
#include "Directory.h"

struct WorkingFiles;
struct WorkingFilesData;
struct WorkingFile {

    int version = 0;
    AbsolutePath filename;
    Directory directory;
    WorkingFiles& parent;
    std::atomic<long long> counter;
    WorkingFile(WorkingFiles& ,const AbsolutePath& filename, const std::string& buffer_content);
    WorkingFile(WorkingFiles&, const AbsolutePath& filename, std::string&& buffer_content);
    const std::string&  GetContentNoLock() const
    {
        return  buffer_content;
    }
protected:
    friend struct WorkingFiles;
    std::string buffer_content;
};

struct WorkingFiles {

  WorkingFiles();
  ~WorkingFiles();

  void  CloseFilesInDirectory(const std::vector<Directory>&);
  std::shared_ptr<WorkingFile>  OnOpen(lsTextDocumentItem& open);
  std::shared_ptr<WorkingFile>  OnChange(const lsTextDocumentDidChangeParams& change);
  bool  OnClose(const lsTextDocumentIdentifier& close);
  std::shared_ptr<WorkingFile>  OnSave(const lsTextDocumentIdentifier& _save);

  bool GetFileBufferContent(const AbsolutePath& filename, std::wstring& out)
  {
      auto  file = GetFileByFilename(filename);
          if(!file)
          return false;
        return GetFileBufferContent(file, out);
  }
  bool  GetFileBufferContent(const AbsolutePath& filename,std::string& out)
  {
      auto  file = GetFileByFilename(filename);
      if (!file)
          return false;
      return GetFileBufferContent(file, out);
  }
  bool  GetFileBufferContent(std::shared_ptr<WorkingFile>&, std::string& out);
  bool  GetFileBufferContent(std::shared_ptr<WorkingFile>&, std::wstring& out);


  // Find the file with the given filename.
  std::shared_ptr<WorkingFile>   GetFileByFilename(const AbsolutePath& filename);

  void Clear();
private:
  std::shared_ptr<WorkingFile>  GetFileByFilenameNoLock(const AbsolutePath& filename);

  WorkingFilesData* d_ptr;


};