Skip to content

Conversation

@kiitosu
Copy link
Contributor

@kiitosu kiitosu commented Aug 14, 2025

📑 Summary

記事の作成日時、更新日時でソートしたかったので追加しました。日時ソート時は降順でソートさせたかったのでソート順も指定できる様にしました。

記事のソート対象として

  • 記事の作成日時
  • 更新日時

を追加しました。

また、記事のソート順を追加し

  • 昇順
  • 降順

を選択できるようにしました。

image image

📋 Tasks

プルリクエストを作成いただく際、お手数ですが以下の内容についてご確認をお願いします。

  • 📖 Contribution Guide を読んだ
  • 👩‍💻 canary ブランチに対するプルリクエストである
  • 実行して正しく動作しているか確認する
  • 不要なコードが含まれていないか( コメントやログの消し忘れに注意 )
  • XSS になるようなコードが含まれていないか
  • Pull Reuqest の内容は妥当か( 膨らみすぎてないか )

より詳しい内容は Pull Request Policy を参照してください。

if (aStat && bStat) {
// created
if (sortArticle === "created") {
return (aStat.ctime - bStat.ctime) * order;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctimeは作成日時ではなく変更日時のようです。実際にmacOS上で動作確認をするとupdatedAtと同じソートになりました。以下、Claude Codeのコメントです。


VSCode の FileStat の仕様を確認すると:

プロパティ 説明
ctime メタデータの変更時刻(creation timeではない)
mtime 内容の変更時刻

重要: ctime は「作成日時(creation time)」ではありません。POSIX系システムでは「inode変更時刻(change time)」です。ファイルのパーミッション変更などでも更新されます。

そのため、ctime と mtime がほぼ同じ値になるケースが多く、created でソートしても updated と同じ結果になります。

対策案

macOS/Linuxで「真の作成日時(birthtime)」を取得するには、Node.js の fs.stat() を使う必要があります:

  import * as fs from "fs";

  const stat = fs.statSync(filePath);
  console.log(stat.birthtime); // 真の作成日時

ただし、VSCode の workspace.fs.stat() では birthtime は取得できません。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cm-igarashi-ryosuke
ご確認ありがとうございます。
こちらもmacですが、createdとupdatedで挙動は異なっています。
動作確認時のgifを共有いたします。
そちらではどのように確認をされたでしょうか?

Dec-08-2025 20-30-40

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kiitosu ありがとうございます。共有いただいた画面ではうまく動いていそうですね。

私のローカル環境で pnpm dev して立ち上げて動画を撮りました。

2025-12-09.11.39.35.mov

また、各itemのctimeとmtimeをログ出力したのですが、全て同じ値でした。

console.log(`[${item.path}] ctime:${stat.ctime} mtime:${stat.mtime}`);

環境による違いでしょうか(詳細は調べられていないですがご報告まで 🙇 )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらで以下確認すると

console.log(`[${item.path}] ctime:${stat.ctime} mtime:${stat.mtime}`);

ctimeとmtimeの値は異なりますね。
なお、こちらではM1 macで動作確認をしています。
igarashiさんはブラウザで立ち上げてる感じですかね。そうするとctimeがmtimeになってしまうのかもしれません。

nodejsのfsを使おうとしてみたのですが、どうやらブラウザ版のvscodeではnodejsのfsが使えないようでした。(当方フロントエンドに疎く、そのようにgemini,chatgptに言われたという感じです)

となると案としては以下2つのどちらかでしょうか。

  1. ローカルアプリ用にctimeを残す。web版のvscodeではctimeとmtimeのソート結果がおなじになる。
  2. 動作がおなじになることを優先して、ctimeによるソートは削除する

説明するのも難しいので2がいいですかね。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kiitosu ありがとうございます。

まず冒頭のClaude Codeのコメントにつきましては、誤りの可能性が高いです。ctime, mtime はLinuxシステムなどでも使われているキーワードで、混同した可能性が高いです。失礼しました 🙇

VSCode拡張として利用した場合は、ctimeとmtimeは異なる値を返すのですね。

リファレンスを少し調べてみたところ、以下のように記述されていました。
ctime は The creation timestamp と記述されていますので、正しそうです。

ctime: number

The creation timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC.

mtime: number

The modification timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC.

Note: If the file changed, it is important to provide an updated mtime that advanced from the previous value. Otherwise there may be optimizations in place that will not show the updated file contents in an editor for example.

一方、Web拡張につきましては、実行環境が異なり制約があると記述されています。

Web extensions share the same structure as regular extensions, but given the different runtime, don't run with the same code as extensions written for a Node.js runtime. Web extensions still have access to the full VS Code API, but no longer to the Node.js APIs and module loading. Instead, web extensions are restricted by the browser sandbox and therefore have limitations compared to normal extensions.

また、ctime, mtime の具体的な言及はないものの、file system については仮想的な環境であると記述されています。

方針ですが、このプロジェクト自体がWeb拡張向けとして作られているためWeb拡張で動作することを優先したいことと、おそらく最終更新時間の方が利用シーンが多いことを考え、案2(updatedだけを追加)が良いと思いました。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cm-igarashi-ryosuke
作成日ソートを削除しました!

9e4ac55

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kiitosu すみません、動作確認をしていてもう一点問題に気づきました。

Web拡張環境下では、stat.mtime の初期値は実際のファイルの最終更新日時を示しておらず、すべてのファイルでほぼ同じ値になります。

image

VSCode上で更新されることでこの値は更新されますが、更新されていないファイルはファイル名順になり、ソートとしては不完全な状態となります。

不自然にならない方法を考えてみたのですがいい方法が思いつかず。アイディアありましたらお願いします 🙇

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほどー。WEB拡張環境だとなかなか厄介なんですね。私もちょっと難しいのかなと思いました。本PRはcloseするのがいいですかね。

Copy link
Member

@cm-igarashi-ryosuke cm-igarashi-ryosuke Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kiitosu そうですね。技術的な解決、もしくは、UI上の工夫でやりたいことが実現できれば良いのですが。

ちなみに github.dev で 標準のエクスプローラーのソートを更新日時順にする設定があったので試してみたのですが、やはり実際のファイルの更新日時順にはならなかったので、難しいのかもしれません。

image

ここまでご対応いただいたのに申し訳ないです。

Copy link
Member

@cm-igarashi-ryosuke cm-igarashi-ryosuke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kiitosu 確認が遅くなってすみません!!!変更については取り込みたいと考えております。動作確認をして1点正しく動作しない点がありましたのでコメントしました。ご確認をお願い致します。

@kiitosu
Copy link
Contributor Author

kiitosu commented Dec 18, 2025

@cm-igarashi-ryosuke
いえいえ、こちらこそweb拡張環境での動作確認を全くしておらずお手数とおかけしてしまいました 🙇
ではクローズしちゃいますね!

@kiitosu kiitosu closed this Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants