Skip to content

Inactive region highlight#1482

Merged
grdowns merged 22 commits into
masterfrom
inactive-region-highlight
Jan 25, 2018
Merged

Inactive region highlight#1482
grdowns merged 22 commits into
masterfrom
inactive-region-highlight

Conversation

@grdowns

@grdowns grdowns commented Jan 23, 2018

Copy link
Copy Markdown
Contributor

Prepare for inactive region highlighting feature by adding a notification to client.ts for text decoration. Also fix the deprecated changes in launch.json + add some auto-generated changes which are seemingly necessary.

@grdowns grdowns requested a review from bobbrow January 23, 2018 01:11
Comment thread Extension/package.json Outdated
@@ -1115,8 +3759,8 @@
"darwin"
],
"binaries": [
"./bin/Microsoft.VSCode.CPP.Extension.darwin",
"./bin/Microsoft.VSCode.CPP.IntelliSense.Msvc.darwin"
"/home/griffin/vs/vscode-cpptools/Extension/bin/Microsoft.VSCode.CPP.Extension.darwin",

@sean-mcmanus sean-mcmanus Jan 23, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This change to package.json needs to be reverted. Before making any changes to package.json, you need to make sure to undo the changes that occur when re-write the package.json with the runtime version of the file. The make your changes and stage the changes before running the extension again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching that! Is there any way we can automate this process for the future? I would like to investigate the possibility if it's worthwhile.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm going to add a new option to our CMakeLists.txt for the language server that will point to your local clone of this instance and copy it into a disposable location so you don't have to run the extension on top of the local repository. (this has been bugging me as well) :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Excellent! I will revert the changes as per Sean's comment and keep my eyes peeled for that change in the future.

@sean-mcmanus sean-mcmanus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure why GitHub has me doing 2 reviews.

Comment thread Extension/src/LanguageServer/client.ts Outdated
};
let textEditorDecoration = vscode.window.createTextEditorDecorationType(renderOptions);

let editor = vscode.window.visibleTextEditors.find(e => e.document.uri.toString() == params.uri); // TODO change to document.uri == params.uri

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What does this TODO mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a TODO that I should have investigated earlier. Most operations within client.ts operate via vscode.Uri, whereas this method only compares the absolute file path via string. @bobbrow opinion on the matter?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should probably send the uri in the JSON message instead of the filename.

Comment thread Extension/src/LanguageServer/client.ts Outdated

private updateInactiveRegions(params: InactiveRegionParams): void {
let renderOptions: vscode.DecorationRenderOptions = {
color: "rgba(255,0,255,0.5)"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

rgba(255,0,255,0.5) [](start = 20, length = 19)

it looks like we still have the test color in here. We need to remember to make a light-themed and dark-themed gray color here,

@grdowns grdowns Jan 23, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Most definitely. I will add different coloration based on light/dark, and I will keep note of it as a discussion point when we talk as a group, and when we find out more about the possibility of opacity.

Comment thread Extension/src/LanguageServer/client.ts Outdated
let renderOptions: vscode.DecorationRenderOptions = {
color: "rgba(255,0,255,0.5)"
};
let textEditorDecoration = vscode.window.createTextEditorDecorationType(renderOptions);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

let textEditorDecoration = vscode.window.createTextEditorDecorationType(renderOptions); [](start = 8, length = 87)

We probably only need to create this object once when the class is first initialized.

Comment thread Extension/src/LanguageServer/client.ts Outdated
let textEditorDecoration = vscode.window.createTextEditorDecorationType(renderOptions);

let editor = vscode.window.visibleTextEditors.find(e => e.document.uri.toString() == params.uri); // TODO change to document.uri == params.uri
editor.setDecorations(textEditorDecoration, params.ranges);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

editor.setDecorations [](start = 8, length = 21)

with each notification, I think we'll need to save the ranges that come in. This way we can clear out the old decorations before setting the new ones.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like you might also be able to call dispose on the TextEditorDecorationType to remove all decorations associated with that object. If that's the case, then my previous comment about creating the TextEditorDecorationType only once would be invalid. You might be able to just keep a reference to the previous TextEditorDecorationType and dispose it before creating a new one and assigning it to the new ranges.


In reply to: 163304083 [](ancestors = 163304083)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That sounds like a fairly tidy way to manage the decoration types. I will make sure to investigate that possibility first!

Comment thread Extension/ThirdPartyNotices.Mono.txt Outdated
@@ -0,0 +1,170 @@

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is only needed for OSX. Please do not include this in the check-in.

I think it would be ok to add this to the .gitignore. @pieandcakes?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@grdowns Was this added on purpose because you have a requirement for Mono now?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No, I'm pretty sure we don't have a requirement for Mono with this change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This license was auto-generated. I believe Sean is correct and it will be removed.

Comment thread Extension/cpptools.json Outdated
@@ -1,3 +1,3 @@
{
"intelliSenseEngine_default_percentage": 100
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

git diff says this is a whitespace difference, specifically a carriage return (^M). Undo.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will make sure to undo this change. Do we have any tools for Git to automatically ignore carriage return changes? I feel that checking for carriage returns manually with each commit is wasteful.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could try git diff -w | git apply --cached --ignore-whitespace. However, I would do a quick glance atgit diff before creating the PR.

The common things to look out for with this repo is any changes that you did not make or files that you did not add should not be included with your changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I appreciate the advice + tip. You are totally right about the automatically generated changes and I will make sure to be diligent in scrutinizing these diffs pre-PR.

"--pack_alignment",
"8",
"--framework_include_directory=/System/Library/Frameworks"
"8"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this a required change?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should go in at some point though it's not required to be part of this change. This repo is out of sync with the language server.

Comment thread Extension/ThirdPartyNotices.Mono.txt Outdated
@@ -0,0 +1,170 @@

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@grdowns Was this added on purpose because you have a requirement for Mono now?

Comment thread Extension/package.json
@@ -38,7 +38,25 @@
"Linters"
],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you need to undo this file change. I dont' think we should be changing our activation from *.

Comment thread Extension/src/LanguageServer/client.ts Outdated
this.model.tagParserStatus.Value = notificationBody.status;
}

private decoration : vscode.TextEditorDecorationType;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please move this up to the top of the class definition with the other member variables. You might also want to rename it something more specific so we don't lose track of it. e.g. inactiveRegionsDecoration.

Comment thread Extension/src/LanguageServer/client.ts Outdated

// Recycle the active text decorations when we receive a new set of inactive regions
if (this.inactiveRegionsDecoration !== undefined) {
this.inactiveRegionsDecoration.dispose();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thinking about this a bit more... Since the inactiveRegionsDecorarion is linked to the Client, this will end up accidentally deleting highlights from files when you have more than one file open in the editor. You're going to want to have one of these for each uri that you encounter.

And then you will want to add disposal code to DefaultClient.dispose

"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out/src",
"outFiles": ["${workspaceRoot}/out/src"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reading the helptext on outFiles, looks like its a glob pattern to specify js files. do we want to set this to "${workspaceRoot}/out/src/**/*.js" ?

@bobbrow bobbrow dismissed WardenGnaw’s stale review January 24, 2018 18:44

issue is addressed

Comment thread Extension/src/LanguageServer/client.ts Outdated
private crashTimes: number[] = [];
private failureMessageShown = new PersistentState<boolean>("DefaultClient.failureMessageShown", false);
private isSupported: boolean = true;
private inactiveRegionsDecorations = new Map<string, [vscode.TextEditorDecorationType, vscode.Range[]]>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Can you make this an interface?
valuePair[0].dispose(); is not as readable as valuePair.decoration.dispose();
and valuePair[1] = params.ranges; vs valuePair.ranges = params.ranges;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Absolutely! I considered doing so, but decided against it as it didn't seem worth polluting the file + namespace. I think that someone else requesting an interface is enough to rationalize doing it, however. I'll put it through!

Comment thread Extension/src/LanguageServer/client.ts Outdated
//Apply text decorations to inactive regions
for (let e of editors) {
let valuePair: [vscode.TextEditorDecorationType, vscode.Range[]] = this.inactiveRegionsDecorations.get(e.document.uri.toString());
e.setDecorations(valuePair[0], valuePair[1]); // VSCode clears the decorations when the text editor becomes invisible

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

need to guard against valuePair being undefined here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Guard has been brought back in + using if (valuePair) instead of if (valuePair !== undefined)

Comment thread Extension/src/LanguageServer/client.ts Outdated

private updateInactiveRegions(params: InactiveRegionParams): void {
let renderOptions: vscode.DecorationRenderOptions = {
light: { color: "rgba(125,125,125,1.0)" },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: personal preference (being a Light user 😄): I built this change and am playing with it. This is a bit too dark to easily distinguish the inactive regions for me. Can you bump it up a bit? 175,175,175 looks a bit better to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Definitely! I don't expect these numbers to survive until the feature is complete

Comment thread Extension/src/LanguageServer/client.ts Outdated
return new NullClient();
}

interface decorationRangesPair {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Please move it closer to the other group of interfaces.

Comment thread Extension/src/LanguageServer/client.ts Outdated
return new NullClient();
}

interface decorationRangesPair {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Captitalize

Comment thread Extension/src/LanguageServer/client.ts Outdated
//Apply text decorations to inactive regions
for (let e of editors) {
let valuePair: decorationRangesPair = this.inactiveRegionsDecorations.get(e.document.uri.toString());
//if (valuePair !== undefined) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this commented out?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it should be uncommented.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bobbrow is correct. Apologies while I get used to the code review cycle. All tips and advice and nitpicks are welcome. 😄

Comment thread Extension/src/LanguageServer/client.ts Outdated
valuePair.decoration.dispose();
valuePair.decoration = decoration;

valuePair.ranges = params.ranges; // As vscode.TextEditor.setDecorations only applies to visible editors, we must cache the range for when another editor becomes visible

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: move comment above

Comment thread Extension/src/LanguageServer/client.ts Outdated

// Recycle the active text decorations when we receive a new set of inactive regions
let valuePair: decorationRangesPair = this.inactiveRegionsDecorations.get(params.uri);
if (valuePair !== undefined) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Either do !valuePair or this.inactiveRegionsDecorations.has(params.uri)

@grdowns grdowns Jan 24, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

!valuePair changes the meaning of the statement, and this.inactiveRegionsDecorations.has(params.uri) is (assumedly) as expensive as calling this.inactiveRegionsDecorations.get(params.uri) which while minor it would be best to avoid it. Is that the case?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no need to call .has. You can change it to if (valuePair) or just leave it as if (valuePair !== undefined). I think the 'truthy' compare argument for this case has been bolstered a bit by the recent regression, but I believe the API contract here is relatively well defined.

interface Map<K, V> {
    clear(): void;
    delete(key: K): boolean;
    forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
    get(key: K): V | undefined;
    has(key: K): boolean;
    set(key: K, value: V): this;
    readonly size: number;
}

@WardenGnaw WardenGnaw Jan 24, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Whoops, should have looked at the return values of get(). 🙈

-resolved-

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe if (valuePair) is more idiomatic and as it does not change the meaning of the statement, I will substitute it in. Thanks

Comment thread Extension/src/LanguageServer/client.ts Outdated
import { DataBinding } from './dataBinding';
import minimatch = require("minimatch");
import * as logger from '../logger';
import { deactivate } from './extension';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should not be imported here. Only vscode should ever call this method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That snuck in via autocomplete. Removed + noted for the future

return false;
}
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

return true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🤦‍♂️

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I was ignorant of the reference vs primitive comparison difference in this case. if (!e1 == e2) should be if (!e1.isEqual(e2)) as it will compare the ints inside each range's positions.

Comment thread Extension/src/LanguageServer/client.ts Outdated
}

// Helper method to compare two ranges for equality
private isRangesEqual(r1: vscode.Range[], r2: vscode.Range[]): boolean {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: comparing two things. Use "are" instead of "is" for the naming. :)

@grdowns grdowns Jan 25, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's a stylistic choice for a method returning a boolean. But I see your point and I'll concede. 😆

Comment thread Extension/src/LanguageServer/client.ts Outdated

for (let e1 of r1) {
for (let e2 of r2) {
if (!e1.isEqual(e2)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems wrong. It will compare r1[0] against r2[1] and fail. If we are expecting the arrays to have the same ranges in the same order, this should be a single for-loop iterating from 0 to r1.length-1 (or r2.length-1 since they are equal at this point). Then it checks if r1[n] is equal to r2[n].

@WardenGnaw WardenGnaw Jan 25, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are the arrays always going to have the Range in the same order?

If we are not guaranteedsame order, I think it should be e1 exists in e2, if it does not return false.

@grdowns grdowns Jan 25, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

D'oh. This is n squared as well as ineffective. Thanks

Comment thread Extension/src/LanguageServer/client.ts Outdated
// Recycle the active text decorations when we receive a new set of inactive regions
let valuePair: DecorationRangesPair = this.inactiveRegionsDecorations.get(params.uri);
if (valuePair) {
// The language server will send notifications regardless of whether the ranges have changed. Unfortunately we must check for changes ourselves

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The "unfortunately" part of this comment is implying that there is a problem with the language server we are working around. As we discussed earlier, we are making a conscious choice to do it this way and avoid a second copy of the cached results in the language server. Perhaps this is unfortunate, but it is deliberate, and I don't think this comment helps us understand the code better or feel better about that decision, so my vote is to remove it. 😉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point! I totally agree with that and it will be removed. 😄

@WardenGnaw

Copy link
Copy Markdown
Member

@grdowns grdowns merged commit 572f21a into master Jan 25, 2018
@grdowns grdowns deleted the inactive-region-highlight branch January 25, 2018 22:31
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants