Skip to content

MATLAB language server - v1.3.1 #56

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

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ MATLAB language server supports these editors by installing the corresponding ex

### Unreleased

### 1.3.1
Release date: 2025-01-23

Added:
* The language server keeps the MATLAB path in sync with the client workspace, improving code navigation, completions, and execution

Fixed:
* Resolves errors with document formatting when using with MATLAB R2025a
* Resolves errors with execution and debugging when using with MATLAB R2022a

### 1.3.0
Release date: 2024-12-18

Expand Down
2 changes: 1 addition & 1 deletion matlab/+matlabls/+handlers/FormatSupportHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function handleFormatRequest (this, msg)
cleanupObj3 = setTemporaryValue(s.matlab.editor.tab.IndentSize, msg.tabSize); %#ok<NASGU>

% Format code
response.data = indentcode(codeToFormat, 'matlab'); % This will pull from the user's MATLAB® settings.
response.data = indentcode(codeToFormat); % This will pull from the user's MATLAB® settings.

% Send formatted code
responseChannel = strcat(this.ResponseChannel, '/', msg.channelId);
Expand Down
75 changes: 75 additions & 0 deletions matlab/+matlabls/+handlers/PathSynchronizerHandler.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
classdef (Hidden) PathSynchronizerHandler < matlabls.handlers.FeatureHandler
% PATHSYNCHRONIZERHANDLER The feature handler to support synchronizing the MATLAB path
% with the client's workspace. This provides access points to add and remove from the path,
% as well as get/set MATLAB's current working directory.

% Copyright 2024 The MathWorks, Inc.

properties (Access = private)
CdRequestChannel = "/matlabls/pathSynchronizer/cd/request"

PwdRequestChannel = "/matlabls/pathSynchronizer/pwd/request"
PwdResponseChannel = "/matlabls/pathSynchronizer/pwd/response"

AddPathRequestChannel = "/matlabls/pathSynchronizer/addpath/request"
RmPathRequestChannel = "/matlabls/pathSynchronizer/rmpath/request"
end

methods
function this = PathSynchronizerHandler ()
this.RequestSubscriptions(1) = matlabls.internal.CommunicationManager.subscribe(this.CdRequestChannel, @this.handleCdRequest);
this.RequestSubscriptions(2) = matlabls.internal.CommunicationManager.subscribe(this.PwdRequestChannel, @this.handlePwdRequest);
this.RequestSubscriptions(3) = matlabls.internal.CommunicationManager.subscribe(this.AddPathRequestChannel, @this.handleAddPathRequest);
this.RequestSubscriptions(4) = matlabls.internal.CommunicationManager.subscribe(this.RmPathRequestChannel, @this.handleRmPathRequest);
end
end

methods (Access = private)
function handleCdRequest (~, msg)
path = msg.path;

try
cd(path)
catch e
disp('Error during `cd` operation:')
disp(e.message)
end
end

function handlePwdRequest (this, msg)
try
currentPath = pwd();

responseChannel = strcat(this.PwdResponseChannel, '/', msg.channelId);
matlabls.internal.CommunicationManager.publish(responseChannel, currentPath);
catch e
disp('Error during `pwd` operation:')
disp(e.message)
end
end

function handleAddPathRequest (~, msg)
paths = msg.paths;
paths = strjoin(paths, pathsep);

try
addpath(paths)
catch e
disp('Error during `addpath` operation:')
disp(e.message)
end
end

function handleRmPathRequest (~, msg)
paths = msg.paths;
paths = strjoin(paths, pathsep);

try
rmpath(paths)
catch e
disp('Error during `rmpath` operation:')
disp(e.message)
end
end
end
end
1 change: 1 addition & 0 deletions matlab/+matlabls/MatlabLanguageServerHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function initializeFeatureHandlers (this)
this.FeatureHandlers(end + 1) = matlabls.handlers.LintingSupportHandler();
this.FeatureHandlers(end + 1) = matlabls.handlers.NavigationSupportHandler();
this.FeatureHandlers(end + 1) = matlabls.handlers.FoldingSupportHandler();
this.FeatureHandlers(end + 1) = matlabls.handlers.PathSynchronizerHandler();
end
end
end
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "matlab-language-server",
"version": "1.3.0",
"version": "1.3.1",
"description": "Language Server for MATLAB code",
"main": "./src/index.ts",
"bin": "./out/index.js",
Expand Down
7 changes: 3 additions & 4 deletions src/debug/DebugServices.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 The MathWorks, Inc.
// Copyright 2024-2025 The MathWorks, Inc.

import { IMVM } from '../mvm/impl/MVM'
import EventEmitter from 'events';
Expand Down Expand Up @@ -78,7 +78,7 @@ enum Events {

export class DebugServices extends EventEmitter {
static Events = Events;
private _mvm: IMVM;
private readonly _mvm: IMVM;

constructor (mvm: IMVM) {
super();
Expand All @@ -93,10 +93,9 @@ export class DebugServices extends EventEmitter {
this._mvm.on('ContinueExecutionEvent', (data: MatlabData) => {
this.emit(DebugServices.Events.DBCont);
});
this._mvm.on('ChangeCurrentWorkspace', (data: MatlabData) => {
this._mvm.on('ChangeCurrentWorkspaceEvent', (data: MatlabData) => {
this.emit(DebugServices.Events.DBWorkspaceChanged);
});

this._mvm.on('AddLineNumberBreakpointEvent', (data: MatlabData) => {
this.emit(DebugServices.Events.BreakpointAdded, new BreakpointInfo(data.Filespec, data.LineNumber, data.Condition, data.whichAnonymousFunctionOnCurrentLine));
});
Expand Down
Loading
Loading