LuaLS / LuaLS/lua-language-server
[Feature Request] Interfaces and Implementors
まだ誰も着手していません。
- 主要言語
- Lua
- スター
- 4.4k
- フォーク
- 442
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
The current class system is alright, but imagine this: I have a Stream class which is extended by ReadStream, WriteStream, SeekableStream, etc.
---@class Stream
---@field close fun() Deallocates or hangs up a stream.
---@class SeekableStream: Stream
---@field seek fun(whence: SeekWhence, offset: integer): integer
---@class ReadStream: Stream
---@field read fun(self: ReadStream, length: integer): string|nil
---@class WriteStream: Stream
---@field write fun(data: string): integer
---@class StringStream: ReadStream, SeekableStream Streams data out of a string.
Now I have a function which takes any Seekable, Readable string. How do I specify this? Either we need a conjunction type (ReadStream & SeekableStream, which has keys from both), or we need (preferably) interfaces, which are generic and can be extended by classes. The reason I suggest interfaces is because if I write this:
---@param length integer
---@return string|nil
function StringStream:read(length)
if self.buffer == nil then
error("Stream is closed", 2)
end
if self.cursor > #self.buffer then
return nil
end
local out = string.sub(self.buffer, self.cursor, math.min(#self.buffer, self.cursor + length))
self.cursor = self.cursor + #out
return out
end
and I omit the type annotation, it assumes read is already defined because StringStream extends ReadStream, and it doesn't validate types (arguments and return type are any).
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Issue で説明されているクラス継承と型アノテーションの動作から始め、Stream、ReadStream、SeekableStream、StringStream の例も確認してください。提案されている conjunction type と interface のアプローチを比較し、その後、実装側で独自のアノテーションを省略した場合でも、継承されたメソッドのアノテーションによって引数と戻り値の型が引き続き検証されることを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- developer-experience, devtools
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100