runtime(hare): update for Hare 0.25.2

closes: #18222

Signed-off-by: Amelia Clarke <selene@perilune.dev>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Amelia Clarke
2025-09-08 15:30:41 -04:00
committed by Christian Brabandt
parent 6bb16d2cee
commit 6d68508e62
11 changed files with 860 additions and 411 deletions

View File

@ -3,7 +3,7 @@ vim9script
# Vim functions for file type detection
#
# Maintainer: The Vim Project <https://github.com/vim/vim>
# Last Change: 2025 Sep 04
# Last Change: 2025 Sep 08
# Former Maintainer: Bram Moolenaar <Bram@vim.org>
# These functions are moved here from runtime/filetype.vim to make startup
@ -441,29 +441,29 @@ export def FTfs()
endif
enddef
# Recursively search for Hare source files in a directory and any
# subdirectories, up to a given depth.
# Recursively searches for Hare source files within a directory, up to a given
# depth.
def IsHareModule(dir: string, depth: number): bool
if depth <= 0
return !empty(glob(dir .. '/*.ha'))
if depth < 1
return false
elseif depth == 1
return !glob(dir .. '/*.ha')->empty()
endif
return reduce(sort(glob(dir .. '/*', true, true),
(a, b) => isdirectory(a) - isdirectory(b)),
(acc, n) => acc
# Check all files in the directory before recursing into subdirectories.
return glob(dir .. '/*', true, true)
->sort((a, b) => isdirectory(a) - isdirectory(b))
->reduce((acc, n) => acc
|| n =~ '\.ha$'
|| isdirectory(n)
&& IsHareModule(n, depth - 1),
|| isdirectory(n) && IsHareModule(n, depth - 1),
false)
enddef
# Determine if a README file exists within a Hare module and should be given the
# Haredoc filetype.
# Determines whether a README file is inside a Hare module and should receive
# the 'haredoc' filetype.
export def FTharedoc()
if exists('g:filetype_haredoc')
if IsHareModule('<afile>:h', get(g:, 'haredoc_search_depth', 1))
setf haredoc
endif
if IsHareModule('<afile>:h', get(g:, 'filetype_haredoc', 1))
setf haredoc
endif
enddef

View File

@ -1,26 +1,82 @@
" Vim autoload file.
" Language: Hare
" Maintainer: Amelia Clarke <selene@perilune.dev>
" Last Updated: 2024-05-10
" Upstream: https://git.sr.ht/~sircmpwn/hare.vim
vim9script
" Attempt to find the directory for a given Hare module.
function hare#FindModule(str)
let path = substitute(trim(a:str, ':', 2), '::', '/', 'g')
let dir = finddir(path)
while !empty(path) && empty(dir)
let path = substitute(path, '/\?\h\w*$', '', '')
let dir = finddir(path)
endwhile
return dir
endfunction
# Helper functions for Hare.
# Language: Hare
# Maintainer: Amelia Clarke <selene@perilune.dev>
# Last Updated: 2025 Sep 06
# Upstream: https://git.sr.ht/~sircmpwn/hare.vim
" Return the value of HAREPATH if it exists. Otherwise use a reasonable default.
function hare#GetPath()
if empty($HAREPATH)
return '/usr/src/hare/stdlib,/usr/src/hare/third-party'
# Returns the value of HAREPATH, if it exists. Otherwise, returns a safe
# default.
export def GetPath(): string
var path: list<string>
if !empty($HAREPATH)
path = split($HAREPATH, ':')
else
path = ParsePath()
if empty(path)
return '/usr/src/hare/stdlib,/usr/src/hare/third-party'
endif
endif
return substitute($HAREPATH, ':', ',', 'g')
endfunction
return mapnew(path, (_, n) => escape(n, ' ,;'))->join(',')
enddef
" vim: et sts=2 sw=2 ts=8
# Converts a module identifier into a path.
export def IncludeExpr(): string
var path = trim(v:fname, ':', 2)->substitute('::', '/', 'g')
# If the module cannot be found, it might be a member instead. Try removing
# the final component until a directory is found.
while !finddir(path)
const head = fnamemodify(path, ':h')
if head == '.'
break
endif
path = head
endwhile
return path
enddef
# Modifies quickfix or location list entries to refer to the correct paths after
# running :make or :lmake, respectively.
export def QuickFixPaths()
var GetList: func
var SetList: func
if expand('<amatch>') =~ '^l'
GetList = function('getloclist', [0])
SetList = function('setloclist', [0])
else
GetList = function('getqflist')
SetList = function('setqflist')
endif
final list = GetList({ items: 0 })
for n in list.items
if !empty(n.module)
n.filename = findfile(n.module)
endif
endfor
SetList([], 'r', list)
enddef
# Attempts to parse the directories in $HAREPATH from the output of `hare
# version -v`. Otherwise, returns an empty list.
def ParsePath(): list<string>
if !executable('hare')
return []
endif
silent const lines = systemlist('hare version -v')
const min = match(lines, '^HAREPATH') + 1
if min == 0
return []
endif
const max = match(lines, '^\S', min)
return (max < 0 ? slice(lines, min) : slice(lines, min, max))
->mapnew((_, n) => matchstr(n, '^\s*\zs.*'))
enddef
# vim: et sts=2 sw=2 ts=8 tw=80