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

registerPortAttributesProvider({portRange:[5000,5000]}... doesn't match port 5000 #183846

Closed
andreamah opened this issue May 30, 2023 · 8 comments · Fixed by #184689
Closed

registerPortAttributesProvider({portRange:[5000,5000]}... doesn't match port 5000 #183846

andreamah opened this issue May 30, 2023 · 8 comments · Fixed by #184689
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug remote-explorer Remote explorer view verified Verification succeeded

Comments

@andreamah
Copy link
Contributor

andreamah commented May 30, 2023

Testing #183547

Based on the docs, it's hard to tell whether the range includes the lower and upper number (is the range inclusive of the bounds?). Also, is the array of two numbers a lower and upper range? I feel like I made that assumption myself. It'd be great to specify that in the docs.

Repro steps:

  1. Create a basic extension that runs a server on command:
	let disposable = vscode.commands.registerCommand('testtest.helloWorld', () => {
		// The code you place here will be executed every time your command is executed
		// Display a message box to the user
		vscode.window.showInformationMessage('Hello World from test-ext!');
		
		const server = createServer((request: IncomingMessage, response: ServerResponse) => {
		response.end('Hello world!');
		});
		
		server.listen(port);

	});

and create a ports attribute provider.
2. Set portRange selector to be [5000,5000]
3. When port 5000 is auto-forwarded, it doesn't respect the providePortAttributes provider 🐛

@alexr00 alexr00 added bug Issue identified by VS Code Team member as probable bug remote-explorer Remote explorer view labels May 31, 2023
@alexr00 alexr00 added this to the June 2023 milestone May 31, 2023
@alexr00
Copy link
Member

alexr00 commented Jun 9, 2023

Since other ranges in the API are [inclusive, exclusive] we will keep it consistent here. I'm adding a doc comment and a shorthand for having just one port:

		/**
		 * Specifying a port range will cause your provider to only be called for ports within the range.
		 * The start is inclusive and the end is exclusive. 
		 */
		portRange?: [number, number] | number;

alexr00 added a commit that referenced this issue Jun 9, 2023
alexr00 added a commit that referenced this issue Jun 9, 2023
`registerPortAttributesProvider({portRange:[5000,5000]}...` doesn't match port 5000
Fixes #183846
@vscodenpa vscodenpa added unreleased Patch has not yet been released in VS Code Insiders insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Jun 9, 2023
@andreamah andreamah added verified Verification succeeded and removed verified Verification succeeded labels Jun 28, 2023
@andreamah
Copy link
Contributor Author

I'm still not seeing the portRange being respected when it's a single number. I used vscode.PortAutoForwardAction.Notify and I didn't get a notif. I'm testing in devcontainers prerelease, is there somewhere else I need to test?

@andreamah andreamah reopened this Jun 28, 2023
@andreamah andreamah added the verification-found Issue verification failed label Jun 28, 2023
@vscodenpa vscodenpa removed the insiders-released Patch has been released in VS Code Insiders label Jun 28, 2023
@alexr00
Copy link
Member

alexr00 commented Jun 29, 2023

@andreamah do you set the port range to [5000,5000] or to just 5000?

@alexr00 alexr00 modified the milestones: June 2023, July 2023 Jun 29, 2023
@andreamah
Copy link
Contributor Author

For this, just 5000.

@alexr00
Copy link
Member

alexr00 commented Jul 19, 2023

I am not able to reproduce this. Debugging, I can see that the provider is called when the port is both manually forwarded from the Ports view and when it's auto forwarded. When the port is auto forwarded, I see that the auto forward action is respected. Would you mind testing again during verification this endgame? If you're still seeing the problem let's take a look together.

@alexr00 alexr00 closed this as completed Jul 19, 2023
@alexr00 alexr00 removed the verification-found Issue verification failed label Jul 19, 2023
@andreamah andreamah added the verified Verification succeeded label Jul 27, 2023
@andreamah
Copy link
Contributor Author

Yeah, I'm still seeing this. I'm running in an alpine devcontainer:

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
	const port = 5000;

	// Use the console to output diagnostic information (console.log) and errors (console.error)
	// This line of code will only be executed once when your extension is activated
	console.log('Congratulations, your extension "testtest" is now active!');

	// The command has been defined in the package.json file
	// Now provide the implementation of the command with registerCommand
	// The commandId parameter must match the command field in package.json
	
	vscode.workspace.registerPortAttributesProvider({portRange:port}, {providePortAttributes(
		port: number,
		pid: number | undefined,
		commandLine: string | undefined,
		token: vscode.CancellationToken
	): vscode.ProviderResult<vscode.PortAttributes> {
			return new vscode.PortAttributes(
				vscode.PortAutoForwardAction.Notify
			);
	}});

	let disposable = vscode.commands.registerCommand('testtest.helloWorld', () => {
		// The code you place here will be executed every time your command is executed
		
		const server = createServer((request: IncomingMessage, response: ServerResponse) => {
		response.end('Hello world!');
		});
		
		server.listen(port);

	});

	context.subscriptions.push(disposable);
}

Did I register correctly?

@andreamah andreamah reopened this Jul 27, 2023
@andreamah andreamah removed the verified Verification succeeded label Jul 27, 2023
@andreamah andreamah added feature-request Request for new features or functionality verification-found Issue verification failed and removed feature-request Request for new features or functionality labels Jul 27, 2023
@andreamah andreamah modified the milestones: July 2023, August 2023 Jul 27, 2023
@alexr00
Copy link
Member

alexr00 commented Jul 28, 2023

Let's debug this together next week.

@alexr00 alexr00 modified the milestones: August 2023, September 2023 Aug 28, 2023
@andreamah andreamah added the verified Verification succeeded label Aug 31, 2023
@andreamah
Copy link
Contributor Author

Debugged offline. I had remote.portsAttributes set with port 5000 to silent.

@alexr00 alexr00 removed the verification-found Issue verification failed label Sep 29, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Oct 15, 2023
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 remote-explorer Remote explorer view verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants