在python中,我可以以某种方式使用#%%作为VS Code大纲中的顶级层次结构吗?

我读了这个。 How can you configure python outline mode in VS Code to show only classes and methods

但是VS Code 1.40.0尚不能做到。 Spyder几乎可以做,但是我想使用VS Code。 我只想做一个。

我能以某种方式使VS Code显示

import cats.Monad
import cats.data.EitherT
import cats.effect.{IO,Sync}
import cats.implicits._

case class User(nick: String,points: Int)

trait UserRepositoryAlg[F[_]] {

  def find(nick: String): F[Either[Error,User]]

  def update(user: User): F[Either[Error,User]]
}

//UserRepositoryInterpreter is parametrized,but we require that F has typeclass Sync,//which would allow us to delay effects with `Sync[F].delay`.
//Sync extends Monad,so we don't need to request is explicitly to be able to use for-comprehension
class UserRepositoryInterpreter[F[_]: Sync] extends UserRepositoryAlg[F] {

  val users: mutable.ListBuffer[User] = ListBuffer()

  override def find(nick: String): F[Either[Error,User]] = for {
    //Finding user will be delayed,until we interpret and run our program. Delaying execution is useful for side-effecting effects,//like requesting data from database,writting to console etc.
    res <- Sync[F].delay(Either.fromOption(users.find(user => user.nick == nick),new Error("Couldn't find user")))
  } yield res


  //we can reuse find method from UserRepositoryInterpreter,but we have to wrap find in EitherT to access returned user
  override def update(user: User): F[Either[Error,User]] = (for {
    found <- EitherT(find(user.nick))
    updated = found.copy(points = found.points + user.points)
  } yield updated).value
}

object Main extends App {

  class Pointer[F[_] : Monad](repo: UserRepositoryAlg[F]) {
    def addPoints(nick: String): EitherT[F,Error,User] = {
      for {
        user <- EitherT(repo.find(nick))
        updated <- EitherT(repo.update(user))
      } yield updated
    }
  }

  //at this point we define,that we want to use IO as our effect monad
  val pointer = new Pointer[IO](new UserRepositoryInterpreter[IO]).addPoints("nick")

  pointer.value.unsafeRunSync() //at the end of the world we run our program

}

    # %% Top hierarchy
    def abc():

    # %% Top hierarchy
    def xyz():

在轮廓上?

还是应该等待下一个版本?

weedssjl 回答:在python中,我可以以某种方式使用#%%作为VS Code大纲中的顶级层次结构吗?

嘿KennylSHIMURA(我是VSCode Python扩展程序的开发人员),

Spyder中的Outline Explorer与VS Code中的Outline窗口的功能不同。两个IDE都具有代码单元的概念(用#%%标记的代码区域)。但是在VS Code中,它们仅用于在文件内部导航以及将块提交到“交互窗口”。它们不会显示在“大纲”窗口中。如果需要,您可以在我们的github页面上作为建议:

https://github.com/microsoft/vscode-python

本文链接:https://www.f2er.com/3137546.html

大家都在问