Skip to content

Commit 4f734ad

Browse files
authored
Merge pull request #38 from mathworks/dklilley-release-1.2.1
MATLAB language server - v1.2.1
2 parents afc590d + 6fd685f commit 4f734ad

27 files changed

+848
-601
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ MATLAB language server supports these editors by installing the corresponding ex
2525

2626
### Unreleased
2727

28+
### 1.2.1
29+
Release date: 2024-04-04
30+
31+
Added:
32+
* Supports connecting to MATLAB when the New Desktop for MATLAB is enabled
33+
34+
Fixed:
35+
* Fixed launching App Designer and Simulink through MATLAB code execution
36+
2837
### 1.2.0
2938
Release date: 2024-03-05
3039

matlab/+matlabls/+handlers/CompletionSupportHandler.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
end
1313

1414
methods
15-
function this = CompletionSupportHandler (commManager)
16-
this = [email protected](commManager);
17-
this.RequestSubscriptions = this.CommManager.subscribe(this.RequestChannel, @this.handleCompletionRequest);
15+
function this = CompletionSupportHandler ()
16+
this.RequestSubscriptions = matlabls.internal.CommunicationManager.subscribe(this.RequestChannel, @this.handleCompletionRequest);
1817
end
1918
end
2019

@@ -30,7 +29,7 @@ function handleCompletionRequest (this, msg)
3029
filteredResults = this.filterCompletionResults(completionResultsStr);
3130

3231
responseChannel = strcat(this.ResponseChannel, '/', msg.channelId);
33-
this.CommManager.publish(responseChannel, filteredResults)
32+
matlabls.internal.CommunicationManager.publish(responseChannel, filteredResults)
3433
end
3534

3635
function compResultsStruct = filterCompletionResults (this, completionResultsStr)

matlab/+matlabls/+handlers/FeatureHandler.m

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
classdef (Hidden) FeatureHandler < matlab.mixin.Heterogeneous & handle
22
%FEATUREHANDLER Serves as the base class for all feature handlers.
33

4-
% Copyright 2022 - 2023 The MathWorks, Inc.
4+
% Copyright 2022 - 2024 The MathWorks, Inc.
55

66
properties
7-
CommManager (1,1) matlabls.internal.CommunicationManager
87
RequestSubscriptions (1,:) uint64 % Holds references to subscriptions
98
end
109

1110
methods
12-
function this = FeatureHandler (commManager)
13-
this.CommManager = commManager;
14-
end
15-
1611
function close (this)
17-
arrayfun(@(subRef) this.CommManager.unsubscribe(subRef), this.RequestSubscriptions)
12+
arrayfun(@(subRef) matlabls.internal.CommunicationManager.unsubscribe(subRef), this.RequestSubscriptions)
1813
end
1914

2015
function destroy (this)

matlab/+matlabls/+handlers/FormatSupportHandler.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
end
1111

1212
methods
13-
function this = FormatSupportHandler (commManager)
14-
this = [email protected](commManager);
15-
this.RequestSubscriptions = this.CommManager.subscribe(this.RequestChannel, @this.handleFormatRequest);
13+
function this = FormatSupportHandler ()
14+
this.RequestSubscriptions = matlabls.internal.CommunicationManager.subscribe(this.RequestChannel, @this.handleFormatRequest);
1615
end
1716
end
1817

@@ -33,7 +32,7 @@ function handleFormatRequest (this, msg)
3332

3433
% Send formatted code
3534
responseChannel = strcat(this.ResponseChannel, '/', msg.channelId);
36-
this.CommManager.publish(responseChannel, response)
35+
matlabls.internal.CommunicationManager.publish(responseChannel, response)
3736
end
3837
end
3938
end

matlab/+matlabls/+handlers/IndexingHandler.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
end
1414

1515
methods
16-
function this = IndexingHandler (commManager)
17-
this = [email protected](commManager);
18-
this.RequestSubscriptions(end + 1) = this.CommManager.subscribe(this.DocumentIndexingRequestChannel, @this.handleDocumentIndexRequest);
19-
this.RequestSubscriptions(end + 1) = this.CommManager.subscribe(this.FolderIndexingRequestChannel, @this.handleFolderIndexRequest);
16+
function this = IndexingHandler ()
17+
this.RequestSubscriptions(end + 1) = matlabls.internal.CommunicationManager.subscribe(this.DocumentIndexingRequestChannel, @this.handleDocumentIndexRequest);
18+
this.RequestSubscriptions(end + 1) = matlabls.internal.CommunicationManager.subscribe(this.FolderIndexingRequestChannel, @this.handleFolderIndexRequest);
2019
end
2120
end
2221

@@ -30,7 +29,7 @@ function handleDocumentIndexRequest (this, msg)
3029
codeData = matlabls.internal.computeCodeData(code, filePath);
3130

3231
responseChannel = strcat(this.DocumentIndexingResponseChannel, '/', msg.channelId);
33-
this.CommManager.publish(responseChannel, codeData)
32+
matlabls.internal.CommunicationManager.publish(responseChannel, codeData)
3433
end
3534

3635
function handleFolderIndexRequest (this, msg)
@@ -126,7 +125,7 @@ function parseFile (this, requestId, filePath, isLastFile)
126125
end
127126

128127
responseChannel = strcat(this.FolderIndexingResponseChannel, '/', requestId);
129-
this.CommManager.publish(responseChannel, msg);
128+
matlabls.internal.CommunicationManager.publish(responseChannel, msg);
130129
end
131130
end
132131
end

matlab/+matlabls/+handlers/LintingSupportHandler.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
end
1313

1414
methods
15-
function this = LintingSupportHandler (commManager)
16-
this = [email protected](commManager);
17-
this.RequestSubscriptions(1) = this.CommManager.subscribe(this.LintingRequestChannel, @this.handleLintingRequest);
18-
this.RequestSubscriptions(2) = this.CommManager.subscribe(this.SuppressDiagnosticRequestChannel, @this.handleDiagnosticSuppressionRequest);
15+
function this = LintingSupportHandler ()
16+
this.RequestSubscriptions(1) = matlabls.internal.CommunicationManager.subscribe(this.LintingRequestChannel, @this.handleLintingRequest);
17+
this.RequestSubscriptions(2) = matlabls.internal.CommunicationManager.subscribe(this.SuppressDiagnosticRequestChannel, @this.handleDiagnosticSuppressionRequest);
1918
end
2019
end
2120

@@ -31,7 +30,7 @@ function handleLintingRequest (this, msg)
3130
response.lintData(cellfun(@isempty, response.lintData)) = [];
3231

3332
responseChannel = strcat(this.LintingResponseChannel, '/', msg.channelId);
34-
this.CommManager.publish(responseChannel, response)
33+
matlabls.internal.CommunicationManager.publish(responseChannel, response)
3534
end
3635

3736
function handleDiagnosticSuppressionRequest (this, msg)
@@ -49,7 +48,7 @@ function handleDiagnosticSuppressionRequest (this, msg)
4948
response.suppressionEdits = matlabls.internal.getDiagnosticSuppressionEdits(code, diagnosticId, diagnosticLine);
5049

5150
responseChannel = strcat(this.SuppressDiagnosticResponseChannel, '/', msg.channelId);
52-
this.CommManager.publish(responseChannel, response);
51+
matlabls.internal.CommunicationManager.publish(responseChannel, response);
5352
end
5453
end
5554
end

matlab/+matlabls/+handlers/NavigationSupportHandler.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
end
1010

1111
methods
12-
function this = NavigationSupportHandler (commManager)
13-
this = [email protected](commManager);
14-
this.RequestSubscriptions = this.CommManager.subscribe(this.ResolvePathRequestChannel, @this.handleResolvePathRequest);
12+
function this = NavigationSupportHandler ()
13+
this.RequestSubscriptions = matlabls.internal.CommunicationManager.subscribe(this.ResolvePathRequestChannel, @this.handleResolvePathRequest);
1514
end
1615
end
1716

@@ -47,7 +46,7 @@ function handleResolvePathRequest (this, msg)
4746
end
4847

4948
responseChannel = strcat(this.ResolvePathResponseChannel, '/', msg.channelId);
50-
this.CommManager.publish(responseChannel, response);
49+
matlabls.internal.CommunicationManager.publish(responseChannel, response);
5150
end
5251
end
5352
end
57 Bytes
Binary file not shown.

matlab/+matlabls/MatlabLanguageServerHelper.m

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
% MATLABLANGUAGESERVERHELPER Class for managing the MATLAB®-side operations
33
% which support the MATLAB Language Server.
44

5-
% Copyright 2022 - 2023 The MathWorks, Inc.
5+
% Copyright 2022 - 2024 The MathWorks, Inc.
66

77
properties
8-
CommManager (1,1) matlabls.internal.CommunicationManager
98
FeatureHandlers (1,:) matlabls.handlers.FeatureHandler
109
end
1110

1211
methods
1312
function this = MatlabLanguageServerHelper ()
14-
this.CommManager = matlabls.internal.CommunicationManager();
13+
matlabls.internal.CommunicationManager.initialize();
1514
this.initializeFeatureHandlers()
1615
end
1716

@@ -27,11 +26,11 @@ function delete (this)
2726
methods (Access = private)
2827
function initializeFeatureHandlers (this)
2928
% Initialize all supported feature handlers
30-
this.FeatureHandlers(end + 1) = matlabls.handlers.CompletionSupportHandler(this.CommManager);
31-
this.FeatureHandlers(end + 1) = matlabls.handlers.FormatSupportHandler(this.CommManager);
32-
this.FeatureHandlers(end + 1) = matlabls.handlers.IndexingHandler(this.CommManager);
33-
this.FeatureHandlers(end + 1) = matlabls.handlers.LintingSupportHandler(this.CommManager);
34-
this.FeatureHandlers(end + 1) = matlabls.handlers.NavigationSupportHandler(this.CommManager);
29+
this.FeatureHandlers(end + 1) = matlabls.handlers.CompletionSupportHandler();
30+
this.FeatureHandlers(end + 1) = matlabls.handlers.FormatSupportHandler();
31+
this.FeatureHandlers(end + 1) = matlabls.handlers.IndexingHandler();
32+
this.FeatureHandlers(end + 1) = matlabls.handlers.LintingSupportHandler();
33+
this.FeatureHandlers(end + 1) = matlabls.handlers.NavigationSupportHandler();
3534
end
3635
end
3736
end

matlab/initmatlabls.m

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,32 @@ function initmatlabls (outFile)
3030
end
3131

3232
function logConnectionData (outFile)
33-
c.matlabPid = feature("getpid");
34-
c.matlabRelease = ['R' version('-release')];
35-
c.sessionKey = dduxinternal.getSessionKey();
33+
releaseInfo = matlabRelease;
3634

37-
connectionData = jsonencode(c);
35+
data.pid = feature("getpid");
36+
data.release = releaseInfo.Release;
37+
data.port = matlabls.internal.CommunicationManager.getSecurePort();
38+
data.certFile = matlabls.internal.CommunicationManager.getCertificateLocation();
39+
data.sessionKey = dduxinternal.getSessionKey();
40+
41+
connectionData = jsonencode(data);
3842

3943
disp(strcat("Printing connection data to file: ", newline, " ", outFile))
4044

41-
f = fopen(outFile, "w");
42-
fprintf(f, "%s\n", connectionData);
43-
fclose(f);
45+
% Write data to a temporary file first, then move to the expected filename to
46+
% avoid a timing issue where partial data may be read from the Node.js layer.
47+
tmpFileName = strcat(outFile, '-tmp');
48+
49+
fid = fopen(tmpFileName, "w");
50+
if (fid == -1)
51+
error("Failed to create temporary connection file.")
52+
end
53+
54+
fprintf(fid, "%s\n", connectionData);
55+
fclose(fid);
56+
57+
status = movefile(tmpFileName, outFile);
58+
if ~status
59+
error("Failed to rename connection file.")
60+
end
4461
end

0 commit comments

Comments
 (0)