Mercurial > vim
changeset 33282:c9c720360002
runtime(kotlin): Add Kotlin runtime files (#13110)
Commit: https://github.com/vim/vim/commit/e30d8e4ce01dc1aca95d25be9fd27c09855fd4be
Author: dkearns <dougkearns@gmail.com>
Date: Mon Sep 18 02:51:22 2023 +1000
runtime(kotlin): Add Kotlin runtime files (https://github.com/vim/vim/issues/13110)
Closes udalov/kotlin-vimhttps://github.com/vim/vim/issues/39
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 17 Sep 2023 19:00:07 +0200 |
parents | 3e78dea9ad87 |
children | 3306c1619a9b |
files | .github/CODEOWNERS runtime/ftplugin/kotlin.vim runtime/indent/kotlin.vim runtime/syntax/kotlin.vim |
diffstat | 4 files changed, 257 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -166,6 +166,7 @@ runtime/ftplugin/javascriptreact.vim @dk runtime/ftplugin/jsonc.vim @izhakjakov runtime/ftplugin/julia.vim @carlobaldassi runtime/ftplugin/kconfig.vim @chrisbra +runtime/ftplugin/kotlin.vim @udalov runtime/ftplugin/less.vim @genoma runtime/ftplugin/liquid.vim @tpope runtime/ftplugin/lua.vim @dkearns @@ -194,7 +195,7 @@ runtime/ftplugin/ps1xml.vim @heaths runtime/ftplugin/pymanifest.vim @ObserverOfTime runtime/ftplugin/python.vim @tpict runtime/ftplugin/qb64.vim @dkearns -runtime/ftplugin/qml.vim @ChaseKnowlden +runtime/ftplugin/qml.vim @ChaseKnowlden runtime/ftplugin/r.vim @jalvesaq runtime/ftplugin/racket.vim @benknoble runtime/ftplugin/readline.vim @dkearns @@ -271,6 +272,7 @@ runtime/indent/javascript.vim @bounceme runtime/indent/json.vim @elzr runtime/indent/jsonc.vim @izhakjakov runtime/indent/julia.vim @carlobaldassi +runtime/indent/kotlin.vim @udalov runtime/indent/krl.vim @KnoP-01 runtime/indent/ld.vim @dkearns runtime/indent/less.vim @genoma @@ -288,7 +290,7 @@ runtime/indent/postscr.vim @mrdubya runtime/indent/prolog.vim @dkearns runtime/indent/ps1.vim @heaths runtime/indent/qb64.vim @dkearns -runtime/indent/qml.vim @ChaseKnowlden +runtime/indent/qml.vim @ChaseKnowlden runtime/indent/r.vim @jalvesaq runtime/indent/racket.vim @benknoble runtime/indent/rapid.vim @KnoP-01 @@ -325,7 +327,7 @@ runtime/plugin/tarPlugin.vim @cecamp runtime/plugin/vimballPlugin.vim @cecamp runtime/plugin/zipPlugin.vim @cecamp runtime/plugin/manpager.vim @Konfekt -runtime/syntax/shared/hgcommitDiff.vim @vegerot +runtime/syntax/shared/hgcommitDiff.vim @vegerot runtime/syntax/abaqus.vim @costerwi runtime/syntax/aidl.vim @dpelle runtime/syntax/amiga.vim @cecamp @@ -408,6 +410,7 @@ runtime/syntax/javascript.vim @fleiner runtime/syntax/jsonc.vim @izhakjakov runtime/syntax/julia.vim @carlobaldassi runtime/syntax/kconfig.vim @chrisbra +runtime/syntax/kotlin.vim @udalov runtime/syntax/krl.vim @KnoP-01 runtime/syntax/less.vim @genoma runtime/syntax/lex.vim @cecamp @@ -450,7 +453,7 @@ runtime/syntax/ps1xml.vim @heaths runtime/syntax/psl.vim @danielkho runtime/syntax/pymanifest.vim @ObserverOfTime runtime/syntax/qb64.vim @dkearns -runtime/syntax/qml.vim @ChaseKnowlden +runtime/syntax/qml.vim @ChaseKnowlden runtime/syntax/r.vim @jalvesaq runtime/syntax/racket.vim @benknoble runtime/syntax/raml.vim @in3d
new file mode 100644 --- /dev/null +++ b/runtime/ftplugin/kotlin.vim @@ -0,0 +1,33 @@ +" Vim filetype plugin file +" Language: Kotlin +" Maintainer: Alexander Udalov +" URL: https://github.com/udalov/kotlin-vim +" Last Change: 7 November 2021 +" 2023 Sep 17 by Vim Project (browsefilter) + +if exists('b:did_ftplugin') | finish | endif +let b:did_ftplugin = 1 + +let s:save_cpo = &cpo +set cpo&vim + +setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:// +setlocal commentstring=//\ %s + +setlocal formatoptions-=t formatoptions+=croqnl +silent! setlocal formatoptions+=j + +setlocal includeexpr=substitute(v:fname,'\\.','/','g') +setlocal suffixesadd=.kt + +let b:undo_ftplugin = "setlocal comments< commentstring< ". + \ "formatoptions< includeexpr< suffixesadd<" + +if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") + let b:browsefilter = "Kotlin Source Files (*.kt, *kts)\t*.kt;*.kts\n" . + \ "All Files (*.*)\t*.*\n" + let b:undo_ftplugin .= " | unlet! b:browsefilter" +endif + +let &cpo = s:save_cpo +unlet s:save_cpo
new file mode 100644 --- /dev/null +++ b/runtime/indent/kotlin.vim @@ -0,0 +1,60 @@ +" Vim indent file +" Language: Kotlin +" Maintainer: Alexander Udalov +" URL: https://github.com/udalov/kotlin-vim +" Last Change: 7 November 2021 +" 2023 Sep 17 by Vim Project (undo_indent) + +if exists('b:did_indent') + finish +endif +let b:did_indent = 1 + +setlocal cinoptions& cinoptions+=j1,L0 +setlocal indentexpr=GetKotlinIndent() +setlocal indentkeys=0},0),!^F,o,O,e,<CR> +setlocal autoindent " TODO ? + +let b:undo_indent = "setlocal autoindent< cinoptions< indentexpr< indentkeys<" + +" TODO teach it to count bracket balance, etc. +function! GetKotlinIndent() + if v:lnum == 0 + return 0 + endif + + let prev_num = prevnonblank(v:lnum - 1) + let prev = getline(prev_num) + let prev_indent = indent(prev_num) + let cur = getline(v:lnum) + + if cur =~ '^\s*\*' + return cindent(v:lnum) + endif + + if prev =~ '^\s*\*/' + let st = prev + while st > 1 + if getline(st) =~ '^\s*/\*' + break + endif + let st = st - 1 + endwhile + return indent(st) + endif + + let prev_open_paren = prev =~ '^.*(\s*$' + let cur_close_paren = cur =~ '^\s*).*$' + let prev_open_brace = prev =~ '^.*\({\|->\)\s*$' + let cur_close_brace = cur =~ '^\s*}.*$' + + if prev_open_paren && !cur_close_paren || prev_open_brace && !cur_close_brace + return prev_indent + shiftwidth() + endif + + if cur_close_paren && !prev_open_paren || cur_close_brace && !prev_open_brace + return prev_indent - shiftwidth() + endif + + return prev_indent +endfunction
new file mode 100644 --- /dev/null +++ b/runtime/syntax/kotlin.vim @@ -0,0 +1,157 @@ +" Vim syntax file +" Language: Kotlin +" Maintainer: Alexander Udalov +" URL: https://github.com/udalov/kotlin-vim +" Last Change: 30 December 2022 + +if exists('b:current_syntax') + finish +endif + +syn keyword ktStatement break continue return +syn keyword ktConditional if else when +syn keyword ktRepeat do for while +syn keyword ktOperator in is by +syn keyword ktKeyword get set out super this where +syn keyword ktException try catch finally throw + +syn keyword ktInclude import package + +" Generated stdlib class names {{{ +" The following is generated by https://github.com/udalov/kotlin-vim/blob/master/extra/generate-stdlib-class-names.main.kts +syn keyword ktType AbstractCollection AbstractCoroutineContextElement AbstractCoroutineContextKey AbstractDoubleTimeSource AbstractIterator AbstractList AbstractLongTimeSource +syn keyword ktType AbstractMap AbstractMutableCollection AbstractMutableList AbstractMutableMap AbstractMutableSet AbstractSet AccessDeniedException Accessor Annotation +syn keyword ktType AnnotationRetention AnnotationTarget Any Appendable ArithmeticException Array ArrayDeque ArrayList AssertionError Boolean BooleanArray BooleanIterator +syn keyword ktType BuilderInference Byte ByteArray ByteIterator CName CallsInPlace CancellationException Char CharArray CharCategory CharDirectionality CharIterator CharProgression +syn keyword ktType CharRange CharSequence CharacterCodingException Charsets ClassCastException Cloneable ClosedFloatingPointRange ClosedRange Collection Comparable +syn keyword ktType ComparableTimeMark Comparator ConcurrentModificationException ConditionalEffect ContextFunctionTypeParams Continuation ContinuationInterceptor ContractBuilder +syn keyword ktType CopyActionContext CopyActionResult CoroutineContext DeepRecursiveFunction DeepRecursiveScope Delegates Deprecated DeprecatedSinceKotlin DeprecationLevel +syn keyword ktType Destructured Double DoubleArray DoubleIterator DslMarker Duration DurationUnit Effect Element EmptyCoroutineContext Entry Enum EnumEntries Error Exception +syn keyword ktType ExperimentalContracts ExperimentalJsExport ExperimentalMultiplatform ExperimentalObjCName ExperimentalObjCRefinement ExperimentalPathApi ExperimentalStdlibApi +syn keyword ktType ExperimentalSubclassOptIn ExperimentalTime ExperimentalTypeInference ExperimentalUnsignedTypes ExtensionFunctionType FileAlreadyExistsException +syn keyword ktType FileSystemException FileTreeWalk FileVisitorBuilder FileWalkDirection Float FloatArray FloatIterator FreezingIsDeprecated Function Function0 Function1 Function10 +syn keyword ktType Function11 Function12 Function13 Function14 Function15 Function16 Function17 Function18 Function19 Function2 Function20 Function21 Function22 Function3 Function4 +syn keyword ktType Function5 Function6 Function7 Function8 Function9 FunctionN Getter Grouping HashMap HashSet HiddenFromObjC HidesFromObjC Ignore IllegalArgumentException +syn keyword ktType IllegalStateException IndexOutOfBoundsException IndexedValue Int IntArray IntIterator IntProgression IntRange InvocationKind Iterable Iterator JsExport JsName +syn keyword ktType JvmDefault JvmDefaultWithCompatibility JvmDefaultWithoutCompatibility JvmField JvmInline JvmMultifileClass JvmName JvmOverloads JvmRecord JvmSerializableLambda +syn keyword ktType JvmStatic JvmSuppressWildcards JvmSynthetic JvmWildcard KAnnotatedElement KCallable KClass KClassifier KDeclarationContainer KFunction KMutableProperty +syn keyword ktType KMutableProperty0 KMutableProperty1 KMutableProperty2 KParameter KProperty KProperty0 KProperty1 KProperty2 KType KTypeParameter KTypeProjection KVariance +syn keyword ktType KVisibility Key Kind KotlinNullPointerException KotlinReflectionNotSupportedError KotlinVersion Lazy LazyThreadSafetyMode Level LinkedHashMap LinkedHashSet List +syn keyword ktType ListIterator Long LongArray LongIterator LongProgression LongRange Map MatchGroup MatchGroupCollection MatchNamedGroupCollection MatchResult Metadata Monotonic +syn keyword ktType MustBeDocumented MutableCollection MutableEntry MutableIterable MutableIterator MutableList MutableListIterator MutableMap MutableSet NoSuchElementException +syn keyword ktType NoSuchFileException NoWhenBranchMatchedException NotImplementedError Nothing NullPointerException Number NumberFormatException ObjCName ObservableProperty +syn keyword ktType OnErrorAction OnErrorResult OpenEndRange OptIn OptionalExpectation OverloadResolutionByLambdaReturnType Pair ParameterName PathWalkOption +syn keyword ktType PropertyDelegateProvider PublishedApi PurelyImplements Random RandomAccess ReadOnlyProperty ReadWriteProperty RefinesInSwift Regex RegexOption Repeatable +syn keyword ktType ReplaceWith RequiresOptIn RestrictsSuspension Result Retention Returns ReturnsNotNull RuntimeException Sequence SequenceScope Set Setter SharedImmutable Short +syn keyword ktType ShortArray ShortIterator ShouldRefineInSwift SimpleEffect SinceKotlin Strictfp String StringBuilder SubclassOptInRequired Suppress Synchronized Target +syn keyword ktType TestTimeSource ThreadLocal Throwable Throws TimeMark TimeSource TimedValue Transient Triple TypeCastException Typography UByte UByteArray UInt UIntArray +syn keyword ktType UIntProgression UIntRange ULong ULongArray ULongProgression ULongRange UShort UShortArray UninitializedPropertyAccessException Unit UnsafeVariance +syn keyword ktType UnsupportedOperationException ValueTimeMark Volatile WithComparableMarks +" }}} + +syn keyword ktModifier annotation companion enum inner abstract final open override sealed vararg dynamic expect actual suspend +syn keyword ktStructure class object interface typealias fun val var constructor init + +syn keyword ktReservedKeyword typeof + +syn keyword ktBoolean true false +syn keyword ktConstant null + +syn keyword ktModifier reified external inline noinline crossinline + +syn match ktModifier "\v<data>\ze\@=.*<(class|object)>" +syn match ktModifier "\v<value>\ze\@=.*<class>" +syn match ktModifier "\v<(tailrec|operator|infix)>\ze\@=.*<fun>" +syn match ktModifier "\v<const>\ze\@=.*<val>" +syn match ktModifier "\v<lateinit>\ze\@=.*<var>" +syn match ktModifier "\v<(internal|private|protected|public)>\ze\@=.*<(class|object|interface|typealias|fun|val|var|constructor|get|set)>" + +syn match ktOperator "\v\?:|::|\<\=? | \>\=?|[!=]\=\=?|<as>\??|[-*+/%]\=?|[!&|]" + +syn keyword ktTodo TODO FIXME XXX contained +syn match ktShebang "\v^#!.*$" +syn match ktLineComment "\v//.*$" contains=ktTodo,@Spell +syn region ktComment matchgroup=ktCommentMatchGroup start="/\*" end="\*/" contains=ktComment,ktTodo,@Spell + +syn region ktDocComment start="/\*\*" end="\*/" contains=ktDocTag,ktTodo,@Spell +syn match ktDocTag "\v\@(author|constructor|receiver|return|since|suppress)>" contained +syn match ktDocTag "\v\@(exception|param|property|throws|see|sample)>\s*\S+" contains=ktDocTagParam contained +syn match ktDocTagParam "\v(\s|\[)\S+" contained +syn match ktComment "/\*\*/" + +syn match ktSpecialCharError "\v\\." contained +syn match ktSpecialChar "\v\\([tbnr'"$\\]|u\x{4})" contained +syn region ktString start='"' skip='\\"' end='"' contains=ktSimpleInterpolation,ktComplexInterpolation,ktSpecialChar,ktSpecialCharError,@Spell +syn region ktString start='"""' end='""""*' contains=ktSimpleInterpolation,ktComplexInterpolation,@Spell +syn match ktCharacter "\v'[^']*'" contains=ktSpecialChar,ktSpecialCharError +syn match ktCharacter "\v'\\''" contains=ktSpecialChar +syn match ktCharacter "\v'[^\\]'" + +syn match ktAnnotation "\v(\w)@<!\@[[:alnum:]_.]*(:[[:alnum:]_.]*)?" +syn match ktLabel "\v\w+\@" +syn match ktLabel "\v(\w)@<=\@\w+" + +syn match ktSimpleInterpolation "\v\$\h\w*" contained +syn region ktComplexInterpolation matchgroup=ktComplexInterpolationBrace start="\v\$\{" end="\v\}" contains=ALLBUT,ktSimpleInterpolation,ktTodo,ktSpecialCharError,ktSpecialChar,ktDocTag,ktDocTagParam + +syn match ktNumber "\v<\d+[_[:digit:]]*(uL?|UL?|[LFf])?" +syn match ktNumber "\v<0[Xx]\x+[_[:xdigit:]]*(uL?|UL?|L)?" +syn match ktNumber "\v<0[Bb][01]+[_01]*(uL?|UL?|L)?" +syn match ktFloat "\v<\d*(\d[eE][-+]?\d+|\.\d+([eE][-+]?\d+)?)[Ff]?" + +syn match ktEscapedName "\v`.*`" + +syn match ktExclExcl "!!" +syn match ktArrow "->" + +syn region ktFold start="{" end="}" transparent fold + +exec "syntax sync ccomment ktComment minlines=10" + +hi def link ktStatement Statement +hi def link ktConditional Conditional +hi def link ktRepeat Repeat +hi def link ktOperator Operator +hi def link ktKeyword Keyword +hi def link ktException Exception +hi def link ktReservedKeyword Error + +hi def link ktInclude Include + +hi def link ktType Type +hi def link ktModifier StorageClass +hi def link ktStructure Structure +hi def link ktTypedef Typedef + +hi def link ktBoolean Boolean +hi def link ktConstant Constant + +hi def link ktTodo Todo +hi def link ktShebang Comment +hi def link ktLineComment Comment +hi def link ktComment Comment +hi def link ktCommentMatchGroup Comment +hi def link ktDocComment Comment +hi def link ktDocTag Special +hi def link ktDocTagParam Identifier + +hi def link ktSpecialChar SpecialChar +hi def link ktSpecialCharError Error +hi def link ktString String +hi def link ktCharacter Character + +hi def link ktAnnotation Identifier +hi def link ktLabel Identifier + +hi def link ktSimpleInterpolation Identifier +hi def link ktComplexInterpolationBrace Identifier + +hi def link ktNumber Number +hi def link ktFloat Float + +hi def link ktExclExcl Special +hi def link ktArrow Structure + +let b:current_syntax = 'kotlin' + +" vim:foldmethod=marker