Skip to content

Commit

Permalink
fix(fmt): libs::offset_to_position (#3447)
Browse files Browse the repository at this point in the history
Co-authored-by: Julius de Bruijn <julius+github@nauk.io>
  • Loading branch information
Druue and Julius de Bruijn committed Nov 25, 2022
1 parent 5161c48 commit b9f9247
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions prisma-fmt/src/code_actions/relations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ fn create_missing_unique<'a>(

let new_text = format!("{separator}{indentation}@@unique([{fields}]){newline}}}");

let start = crate::offset_to_position(model.ast_model().span().end - 1, schema).unwrap();
let end = crate::offset_to_position(model.ast_model().span().end, schema).unwrap();
let start = crate::offset_to_position(model.ast_model().span().end - 1, schema);
let end = crate::offset_to_position(model.ast_model().span().end, schema);

let range = Range { start, end };

Expand Down
8 changes: 4 additions & 4 deletions prisma-fmt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,18 @@ pub(crate) fn range_to_span(range: Range, document: &str) -> ast::Span {

/// Gives the LSP position right after the given span.
pub(crate) fn position_after_span(span: ast::Span, document: &str) -> Position {
offset_to_position(span.end - 1, document).unwrap()
offset_to_position(span.end - 1, document)
}

/// Converts a byte offset to an LSP position, if the given offset
/// does not overflow the document.
pub(crate) fn offset_to_position(offset: usize, document: &str) -> Option<Position> {
pub(crate) fn offset_to_position(offset: usize, document: &str) -> Position {
let mut position = Position::default();

for (i, chr) in document.chars().enumerate() {
match chr {
_ if i == offset => {
return Some(position);
return position;
}
'\n' => {
position.character = 0;
Expand All @@ -191,7 +191,7 @@ pub(crate) fn offset_to_position(offset: usize, document: &str) -> Option<Positi
}
}

None
position
}

#[cfg(test)]
Expand Down

0 comments on commit b9f9247

Please sign in to comment.