Repository navigation
Expand file tree
/
Copy pathdbg_pathconvert.cpp
More file actions
127 lines (118 loc) · 2.98 KB
/
Copy pathdbg_pathconvert.cpp
File metadata and controls
127 lines (118 loc) · 2.98 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "dbg_pathconvert.h"
#include "dbg_path.h"
#include "dbg_impl.h"
#include <algorithm>
#include <assert.h>
namespace vscode
{
pathconvert::pathconvert(debugger_impl* dbg)
: debugger_(dbg)
, sourcemaps_()
{ }
void pathconvert::add_sourcemap(const fs::path& srv, const fs::path& cli)
{
if (srv.is_absolute())
{
sourcemaps_.push_back(std::make_pair(path_normalize(srv), cli));
}
else
{
sourcemaps_.push_back(std::make_pair(path_normalize(fs::absolute(srv, fs::current_path())), cli));
}
}
void pathconvert::clear_sourcemap()
{
sourcemaps_.clear();
}
bool pathconvert::fget(const std::string& server_path, fs::path*& client_path)
{
auto it = server2client_.find(server_path);
if (it != server2client_.end())
{
client_path = &it->second;
return true;
}
return false;
}
fs::path pathconvert::server_complete(const fs::path& path)
{
if (path.is_absolute())
{
return path;
}
return path_normalize(fs::absolute(path, fs::current_path()));
}
pathconvert::result pathconvert::eval_uncomplete(const std::string& server_path, fs::path& client_path)
{
if (server_path[0] == '@')
{
fs::path srvpath = server_complete(server_path.substr(1));
for (auto& pair : sourcemaps_)
{
if (path_is_subpath(srvpath, pair.first))
{
std::error_code ec;
client_path = path_uncomplete(srvpath, pair.first, ec);
assert(!ec);
return result::sucess;
}
}
std::error_code ec;
client_path = path_uncomplete(srvpath, fs::current_path(), ec);
assert(!ec);
return result::sucess;
}
else if (server_path[0] == '=')
{
return debugger_->custom_->path_convert(server_path, client_path, sourcemaps_, true);
}
client_path = server_path;
return result::sucess;
}
pathconvert::result pathconvert::eval(const std::string& server_path, fs::path& client_path)
{
if (server_path[0] == '@')
{
fs::path srvpath = server_complete(server_path.substr(1));
for (auto& pair : sourcemaps_)
{
if (path_is_subpath(srvpath, pair.first))
{
std::error_code ec;
client_path = path_normalize(pair.second / path_uncomplete(srvpath, pair.first, ec));
server2client_[server_path] = client_path;
assert(!ec);
return result::sucess;
}
}
client_path = path_normalize(srvpath);
server2client_[server_path] = client_path;
return result::sucess;
}
else if (server_path[0] == '=')
{
result r = debugger_->custom_->path_convert(server_path, client_path, sourcemaps_, false);
switch (r)
{
case custom::result::failed:
case custom::result::sucess:
server2client_[server_path] = client_path;
break;
}
return r;
}
client_path = server_path;
server2client_[server_path] = client_path;
return result::sucess;
}
pathconvert::result pathconvert::get_or_eval(const std::string& server_path, fs::path& client_path)
{
fs::path* ptr;
if (fget(server_path, ptr))
{
client_path = *ptr;
return result::sucess;
}
return eval(server_path, client_path);
}
}