Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outline should refresh on document mode change #52985

Closed
aeschli opened this issue Jun 26, 2018 · 3 comments
Closed

Outline should refresh on document mode change #52985

aeschli opened this issue Jun 26, 2018 · 3 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug outline Source outline view issues verified Verification succeeded
Milestone

Comments

@aeschli
Copy link
Contributor

aeschli commented Jun 26, 2018

Testing #52797

  • Create extension below
  • open an existing package.json file
  • open the outline and see verify the entries
  • change the editor mode from json to json2
  • outline still shows the old outline (new outline should only have one kind of icons)
'use strict';
import * as vscode from 'vscode';
import { parseTree, Node } from 'jsonc-parser'

export function activate(context: vscode.ExtensionContext) {

    context.subscriptions.push(vscode.languages.registerDocumentSymbolProvider('json2', {
        provideDocumentSymbols(doc: vscode.TextDocument) {
            let node = parseTree(doc.getText());
            if (node) {
                return createDocumentSymbols(node, doc);
            }
            return null;
        }
    }));
}

function createDocumentSymbols(objectNode: Node, doc: vscode.TextDocument): vscode.DocumentSymbol[] {
    if (objectNode.type === 'object') {
        if (objectNode.children) {
            return objectNode.children.map(node => {
                let nameNode = node.children![0];
                let name = nameNode.value.toString();
                let nameRange = new vscode.Range(doc.positionAt(nameNode.offset), doc.positionAt(nameNode.offset + nameNode.length));
                let range = new vscode.Range(doc.positionAt(node.offset), doc.positionAt(node.offset + node.length));
                let symbol = new vscode.DocumentSymbol(name, `property at ${node.offset}`, vscode.SymbolKind.Property, range, nameRange);

                let valueNode = node.children![1];
                if (valueNode.type === 'object') {
                    symbol.children = createDocumentSymbols(valueNode, doc);
                }
                return symbol;
            });
        }
    }
    return [];
}

package.json

    "contributes": {
        "languages": [
            {
                "id": "json2",
                "aliases": [
                    "JSON2"
                ],
                "extensions": [
                    ".json2"
                ]
            }
        ]
    }
@jrieken jrieken added this to the June 2018 milestone Jun 26, 2018
@jrieken jrieken added bug Issue identified by VS Code Team member as probable bug outline Source outline view issues labels Jun 26, 2018
@jrieken
Copy link
Member

jrieken commented Jun 26, 2018

Shouldn't be like that... We do listen on model language change event, maybe something specific to icons... @aeschli Is your provider being called after the change?

@aeschli
Copy link
Contributor Author

aeschli commented Jun 27, 2018

Just tested again. Somtime switching the mode refreshes the outline, other times not. If it not, the provideDocumentSymbols is not called.

@jrieken
Copy link
Member

jrieken commented Jun 27, 2018

This is a good find and slipped in when I added outline model caching...

@aeschli aeschli added the verified Verification succeeded label Jun 28, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Aug 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug outline Source outline view issues verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

2 participants