Coder Social home page Coder Social logo

Comments (11)

lovettchris avatar lovettchris commented on May 28, 2024

I cannot repro this problem the following function has a check to see if the file changed is the "current" lean-toolchain being used by the project, if not then it is ignored.

    private async handleFileChanged(uri: Uri) {
        if (!this.leanVersionFile){
            this.leanVersionFile = uri;
        }

        if (uri.toString() === this.leanVersionFile.toString()) {
            const version = await this.readLeanVersion();
            if (version !== this.currentVersion){
                this.currentVersion = version;
                this.localStorage.setLeanVersion('');
                // raise an event so the extension triggers handleVersionChanged.
                this.versionChangedEmitter.fire(version);
            }
        }
    }

This is what I tried:

  • load folder with a lean-toolchain at the root of the folder, and another lean-toolchain in a subfolder named Foo.
  • Ensure the root version is being used.
  • I then changed the lean-toolchain in the Foo folder

This caused the above code to execute but the if (uri.toString() === this.leanVersionFile.toString()) { caused it to skip and do nothing. So why do I look for all changes? In case the user deletes a file and the current this.leanVersionFile then moves to a different (perhaps inherited) file.

from vscode-lean4.

gebner avatar gebner commented on May 28, 2024

I tried this in the lean4 repository, which has neither a lean-toolchain nor a lakefile.lean (except in the src/lake submodule).

In case the user deletes a file and the current this.leanVersionFile then moves to a different (perhaps inherited) file.

Ah, so we actually look in the parent directories now? Cool. I think we should also do that on every file change event (instead of assuming that the changed file is now the new valid toolchain file).

from vscode-lean4.

lovettchris avatar lovettchris commented on May 28, 2024

Yes I do that already too, in response to the version change, the extension calls leanpkg.testLeanVersion which calls again to pkgService.findLeanPkgVersionInfo which walks up the hierarchy again, so it always uses the "best" file and if it is good, it raises an installChanged event which restarts the lean server, and when "lean --server" runs it seems to apply the same algorithm, searching up the folder hierarchy, so I think we're good.

from vscode-lean4.

gebner avatar gebner commented on May 28, 2024

Something's still not right then. When I open the lean4 directory in vscode, and then do cd src/lake && git checkout HEAD^^^^^^^^^, I still get a popup that the lean version changed. I'm pretty sure it's because we treat the first changed lean-toolchain file as the best file, even if it is in a subdirectory:

    private async handleFileChanged(uri: Uri) {
        if (!this.leanVersionFile){
            this.leanVersionFile = uri;
        }

from vscode-lean4.

Kha avatar Kha commented on May 28, 2024

The logic in getWorkspaceLeanFolderUri also looks a bit dubious - if a Lean file is part of a workspace, we should always use that workspace root to be consistent with the server (which is started from the workspace root, apart from #15).

from vscode-lean4.

lovettchris avatar lovettchris commented on May 28, 2024

When I open the lean4 directory in vscode, and then do cd src/lake && git checkout HEAD^^^^^^^^^

Yes, this is an odd case, lean4 has no toolchain, but it depends on a git submodule that does. So yes, this is picking up and using the lean-toolchain from lake. Is this not what you want though? What do you want in this case?

from vscode-lean4.

lovettchris avatar lovettchris commented on May 28, 2024

The logic in getWorkspaceLeanFolderUri also looks a bit dubious

Which part is dubious? Are you looking at this code?

        if (rootPath) {
            return Uri.joinPath(rootPath, '..');
        }

The reason for this the ".." is because the rootPath at this point is the full URI of the document which is something like file:///d%3A/Temp/lean_examples/Foo/Main.lean but we want the Uri of the folder containing this document.

from vscode-lean4.

Kha avatar Kha commented on May 28, 2024

As I wrote above, we should always look at the file in the workspace root if we're inside a workspace - both when listening for changes to it, and when actually reading the file. We can optionally do the upwards traversal in the case of non-workspace files, though I assume listening for changes doesn't work in that case because the API docs say it only works inside workspaces. In any case, this fringe use case should not affect the behavior inside workspaces, which is the important use case that we need to get consistent with the server.

from vscode-lean4.

Kha avatar Kha commented on May 28, 2024

More precisely, if we want to be fully consistent with elan, we could do an upwards traversal starting from the workspace root. This might be important if someone wants to manage multiple packages inside a single repo with a single lean-toolchain file in the repo root. Though again with the caveat that, if the traversal leaves the opened workspace(s), I believe the file watcher will cease functioning.

from vscode-lean4.

lovettchris avatar lovettchris commented on May 28, 2024

More precisely, if we want to be fully consistent with elan, we could do an upwards traversal starting from the workspace root

Great, that is exactly what findLeanPkgVersionInfo is doing. The only exception is when there is nothing in the workspace root and nothing in the parent hierarchy, which is the case that @gebner pointed to with the lean4 repo. I guess it is a bit inconsistent since it does not find the lean-toolchain in the lake submodule when you open lean4 but only when you change it with a git submodule update... So if you both want me to remove the "**/" I can easily do it...

from vscode-lean4.

lovettchris avatar lovettchris commented on May 28, 2024

Ok, I have fixed this in #83 (please try it again) - it now always applys the findLeanPkgVersionInfo algorithm no matter which file the file watcher found. I also fixed a bug in getWorkspaceLeanFolderUri so that if you open lean4 with D:\git\leanprover\lean4\src\lake\Lake\Version.lean in the editor it does NOT find the lake lean-toolchain file. Perhaps this is what both of you were seeing above which I agree is confusing. It now correctly uses workspace.getWorkspaceFolder(documentUri) to find the workspace folder and starts the search from there. So opening lean4 with no "(default)" toolchain installed now correctly shows this dialog:
image

from vscode-lean4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.