diff options
author | Aleksey Kladov <[email protected]> | 2018-08-17 17:54:08 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-17 17:54:08 +0100 |
commit | ed7ae78c6fd9e508f6e959c6a164cf8481f6b377 (patch) | |
tree | 556e8d4daffefa64dcdc5db8e75299514a0e85e4 /crates/server/src/conv.rs | |
parent | 41570f60bf268c97223a864b8aa11a339929f55a (diff) |
ServerWorld
Diffstat (limited to 'crates/server/src/conv.rs')
-rw-r--r-- | crates/server/src/conv.rs | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/crates/server/src/conv.rs b/crates/server/src/conv.rs index b3709ccaf..fc9056914 100644 --- a/crates/server/src/conv.rs +++ b/crates/server/src/conv.rs | |||
@@ -6,7 +6,10 @@ use libeditor::{LineIndex, LineCol, Edit, AtomEdit}; | |||
6 | use libsyntax2::{SyntaxKind, TextUnit, TextRange}; | 6 | use libsyntax2::{SyntaxKind, TextUnit, TextRange}; |
7 | use libanalysis::FileId; | 7 | use libanalysis::FileId; |
8 | 8 | ||
9 | use {Result, PathMap}; | 9 | use { |
10 | Result, | ||
11 | server_world::ServerWorld, | ||
12 | }; | ||
10 | 13 | ||
11 | pub trait Conv { | 14 | pub trait Conv { |
12 | type Output; | 15 | type Output; |
@@ -126,57 +129,52 @@ impl<T: ConvWith> ConvWith for Option<T> { | |||
126 | } | 129 | } |
127 | 130 | ||
128 | impl<'a> TryConvWith for &'a Url { | 131 | impl<'a> TryConvWith for &'a Url { |
129 | type Ctx = PathMap; | 132 | type Ctx = ServerWorld; |
130 | type Output = FileId; | 133 | type Output = FileId; |
131 | fn try_conv_with(self, path_map: &PathMap) -> Result<FileId> { | 134 | fn try_conv_with(self, world: &ServerWorld) -> Result<FileId> { |
132 | let path = self.to_file_path() | 135 | world.uri_to_file_id(self) |
133 | .map_err(|()| format_err!("invalid uri: {}", self))?; | ||
134 | path_map.get_id(&path).ok_or_else(|| format_err!("unknown file: {}", path.display())) | ||
135 | } | 136 | } |
136 | } | 137 | } |
137 | 138 | ||
138 | impl TryConvWith for FileId { | 139 | impl TryConvWith for FileId { |
139 | type Ctx = PathMap; | 140 | type Ctx = ServerWorld; |
140 | type Output = Url; | 141 | type Output = Url; |
141 | fn try_conv_with(self, path_map: &PathMap) -> Result<Url> { | 142 | fn try_conv_with(self, world: &ServerWorld) -> Result<Url> { |
142 | let path = path_map.get_path(self); | 143 | world.file_id_to_uri(self) |
143 | let url = Url::from_file_path(path) | ||
144 | .map_err(|()| format_err!("can't convert path to url: {}", path.display()))?; | ||
145 | Ok(url) | ||
146 | } | 144 | } |
147 | } | 145 | } |
148 | 146 | ||
149 | impl<'a> TryConvWith for &'a TextDocumentItem { | 147 | impl<'a> TryConvWith for &'a TextDocumentItem { |
150 | type Ctx = PathMap; | 148 | type Ctx = ServerWorld; |
151 | type Output = FileId; | 149 | type Output = FileId; |
152 | fn try_conv_with(self, path_map: &PathMap) -> Result<FileId> { | 150 | fn try_conv_with(self, world: &ServerWorld) -> Result<FileId> { |
153 | self.uri.try_conv_with(path_map) | 151 | self.uri.try_conv_with(world) |
154 | } | 152 | } |
155 | } | 153 | } |
156 | 154 | ||
157 | impl<'a> TryConvWith for &'a VersionedTextDocumentIdentifier { | 155 | impl<'a> TryConvWith for &'a VersionedTextDocumentIdentifier { |
158 | type Ctx = PathMap; | 156 | type Ctx = ServerWorld; |
159 | type Output = FileId; | 157 | type Output = FileId; |
160 | fn try_conv_with(self, path_map: &PathMap) -> Result<FileId> { | 158 | fn try_conv_with(self, world: &ServerWorld) -> Result<FileId> { |
161 | self.uri.try_conv_with(path_map) | 159 | self.uri.try_conv_with(world) |
162 | } | 160 | } |
163 | } | 161 | } |
164 | 162 | ||
165 | impl<'a> TryConvWith for &'a TextDocumentIdentifier { | 163 | impl<'a> TryConvWith for &'a TextDocumentIdentifier { |
166 | type Ctx = PathMap; | 164 | type Ctx = ServerWorld; |
167 | type Output = FileId; | 165 | type Output = FileId; |
168 | fn try_conv_with(self, path_map: &PathMap) -> Result<FileId> { | 166 | fn try_conv_with(self, world: &ServerWorld) -> Result<FileId> { |
169 | self.uri.try_conv_with(path_map) | 167 | world.uri_to_file_id(&self.uri) |
170 | } | 168 | } |
171 | } | 169 | } |
172 | 170 | ||
173 | pub fn to_location( | 171 | pub fn to_location( |
174 | file_id: FileId, | 172 | file_id: FileId, |
175 | range: TextRange, | 173 | range: TextRange, |
176 | path_map: &PathMap, | 174 | world: &ServerWorld, |
177 | line_index: &LineIndex, | 175 | line_index: &LineIndex, |
178 | ) -> Result<Location> { | 176 | ) -> Result<Location> { |
179 | let url = file_id.try_conv_with(path_map)?; | 177 | let url = file_id.try_conv_with(world)?; |
180 | let loc = Location::new( | 178 | let loc = Location::new( |
181 | url, | 179 | url, |
182 | range.conv_with(line_index), | 180 | range.conv_with(line_index), |