1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
4{-# LANGUAGE OverloadedStrings #-}
6-- | Types and functions for working with source code locations.
7module Development.IDE.Types.Location
22import Language.Haskell.LSP.Types (Location(..), Range(..), Position(..), Uri(..), filePathToUri)
24-- | A dummy location to use when location information is missing.
27 { _uri = filePathToUri noFilePath
32noFilePath = "<unknown>"
34-- A dummy range to use when range is unknown
36noRange = Range (Position 0 0) (Position 100000 0)
39-- | A dummy location to use when location information is not present because
40-- the code was generated.
41genLocation :: Location
43 { _uri = Uri "<generated>"
44 , _range = Range (Position 0 0) (Position 0 0)
48-- | Is a location generated.
49isGenLocation :: Location -> Bool
50isGenLocation x = _uri x == Uri "<generated>"
53-- | Check if a position is inside a range.
54-- Our definition states that the start of the range is included, but not the end.
55inRange :: Position -> Range -> Bool
56inRange pos (Range start end) = start <= pos && pos < end
59-- | Check if a position is inside a range, including the end.
60-- Both start and end of the range are included.
61inRangeClosed :: Position -> Range -> Bool
62inRangeClosed pos (Range start end) = start <= pos && pos <= end
65-- | Produce a new range where the minimum position is the min of both,
66-- and the maximum position is the max of both.
67appendRange :: Range -> Range -> Range
69 = Range { _start = min (_start r1) (_start r2)
70 , _end = max (_end r1) (_end r2) }
73-- | Produce a new location where the ranges are the appended and we choose
74-- the file path of the second.
75appendLocation :: Location -> Location -> Location
77 = Location { _uri = _uri l2
78 , _range = appendRange (_range l1) (_range l2) }
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list