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

Vo/active window changes #15

Merged
merged 4 commits into from Mar 6, 2019

Conversation

Projects
None yet
2 participants
@vanesa
Copy link
Member

vanesa commented Mar 6, 2019

WIP: Use activeWindowChanges to keep track changes and ensure window accessibility.

filter((editor): editor is sourcegraph.CodeEditor => editor !== undefined)
)

// When the configuration or current file changes, publish new decorations.

This comment has been minimized.

@lguychard

lguychard Mar 6, 2019

Member
Suggested change
// When the configuration or current file changes, publish new decorations.
// When the active editor changes, publish new decorations.
editor.setDecorations(decorationType, decorations)
})
)
}
}
}
sourcegraph.workspace.onDidOpenTextDocument.subscribe(() =>

This comment has been minimized.

@lguychard

lguychard Mar 6, 2019

Member

You won't be needing this anymore.

const decorationType = sourcegraph.app.createDecorationType()
setTimeout(() => editor.setDecorations(decorationType, decorations), 200)

if (sourcegraph.app.activeWindowChanges) {

This comment has been minimized.

@lguychard

lguychard Mar 6, 2019

Member

This block looks fine, but it should not be contained in the body decorateEditors(). decorateEditors() is also probably useless now. You probably want something like this:

function decorateEditor(editor: sourcegraph.CodeEditor): void {
    // decoration logic goes here
}

export function activate(context: sourcegraph.extension.Context): void {
    // declare `activeEditor` above
    context.subscriptions.add(
        activeEditor.subscribe(decorateEditor)
    )
}
STATSD_PATTERN.lastIndex = 0 // reset
function decorateEditor(editor: sourcegraph.CodeEditor): void {
const decorations: sourcegraph.TextDocumentDecoration[] = []
const decorationType = sourcegraph.app.createDecorationType()

This comment has been minimized.

@lguychard

lguychard Mar 6, 2019

Member

You'll want to create the decorationType at the top level, otherwise you may get duplicate decorations.

const decorationType = sourcegraph.app.createDecorationType()
for (const [i, line] of editor.document.text!.split('\n').entries()) {
let m: RegExpExecArray | null
do {

This comment has been minimized.

@lguychard

lguychard Mar 6, 2019

Member

This do {} while {} feels very unidiomatic. Why do you need it? Can't you simply do the following:

const match = line.match(STATSD_PATTERN)
if (match) {
    // stuff
}

(string.match(regex) returns all matches of a global regExp as an array)

This comment has been minimized.

@lguychard

lguychard Mar 6, 2019

Member

Also, even if you're working on the assumption that there are several matches per line, the decorations you add on the same line will be indistinguishable from each other (they will all read ' View metric (Datadog) » ')

}

export function activate(context: sourcegraph.ExtensionContext): void {
const activeEditor = from(sourcegraph.app.activeWindowChanges).pipe(

This comment has been minimized.

@lguychard

lguychard Mar 6, 2019

Member

This will throw if sourcegraph.app.activeWindowChanges is undefined (which, again, will only happen on < 3.1 instances). Move it into the if block below.

@vanesa vanesa marked this pull request as ready for review Mar 6, 2019

@vanesa vanesa merged commit 86e66ef into master Mar 6, 2019

@vanesa vanesa deleted the vo/activeWindowChanges branch Mar 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.